SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches
RWThreadFunction Class Reference

Handle class for functor-based threaded runnable objects. More...

#include <rw/thread/RWThreadFunction.h>

Inheritance diagram for RWThreadFunction:
RWThread RWRunnable RWRunnableHandle RWHandleBase

Public Member Functions

 RWThreadFunction ()
 
 RWThreadFunction (const RWThreadFunction &second)
 
 ~RWThreadFunction ()
 
RWTFunctor< void()> getFunctor () const
 
RWThreadFunctionoperator= (const RWThreadFunction &second)
 
void setFunctor (const RWTFunctor< void()> &functor)
 
- Public Member Functions inherited from RWThread
 RWThread ()
 
 RWThread (const RWThread &second)
 
 RWThread (RWStaticCtor)
 
 ~RWThread ()
 
bool canGetPriority () const
 
bool canGetProcessScopePriority () const
 
bool canGetSchedulingPolicy () const
 
bool canGetSystemScopePriority () const
 
bool canGetTimeSliceQuantum () const
 
bool canSetPriority () const
 
bool canSetProcessScopePriority () const
 
bool canSetSchedulingPolicy (RWSchedulingPolicy policy) const
 
bool canSetSystemScopePriority () const
 
bool canSetTimeSliceQuantum () const
 
RWThreadAttribute getActiveAttribute () const
 
RWThreadAttribute getAttribute () const
 
RWPriority getMaxPriority () const
 
RWPriority getMaxProcessScopePriority () const
 
RWPriority getMaxSystemScopePriority () const
 
unsigned long getMaxTimeSliceQuantum () const
 
RWPriority getMinPriority () const
 
RWPriority getMinProcessScopePriority () const
 
RWPriority getMinSystemScopePriority () const
 
unsigned long getMinTimeSliceQuantum () const
 
RWPriority getPriority () const
 
RWPriority getProcessScopePriority () const
 
RWThreadSelf getRWThreadSelf () const
 
RWSchedulingPolicy getSchedulingPolicy () const
 
unsigned getSuspendCount () const
 
RWPriority getSystemScopePriority () const
 
unsigned long getTimeSliceQuantum () const
 
RWThreadoperator= (const RWThread &second)
 
unsigned resume ()
 
void setAttribute (const RWThreadAttribute &second)
 
void setPriority (RWPriority priority)
 
void setProcessScopePriority (RWPriority priority)
 
void setSchedulingPolicy (RWSchedulingPolicy policy)
 
void setSystemScopePriority (RWPriority priority)
 
void setTimeSliceQuantum (unsigned long milliseconds)
 
unsigned suspend ()
 
void terminate ()
 
- Public Member Functions inherited from RWRunnable
 RWRunnable ()
 
 RWRunnable (const RWRunnable &second)
 
 RWRunnable (RWStaticCtor)
 
 ~RWRunnable ()
 
RWRunnable getNestedRunnable () const
 
RWRunnableSelf getRWRunnableSelf () const
 
RWWaitStatus join (unsigned long milliseconds)
 
void join (void)
 
RWRunnableoperator= (const RWRunnable &second)
 
void raise () const
 
void releaseInterrupt ()
 
RWWaitStatus requestCancellation ()
 
RWWaitStatus requestCancellation (unsigned long milliseconds)
 
RWWaitStatus requestInterrupt ()
 
RWWaitStatus requestInterrupt (unsigned long milliseconds)
 
RWCompletionState start ()
 
RWExecutionState wait (unsigned long stateMask)
 
RWWaitStatus wait (unsigned long stateMask, RWExecutionState *state, unsigned long milliseconds)
 
- Public Member Functions inherited from RWRunnableHandle
void addCallback (const RWTFunctor< void(const RWRunnable &, RWExecutionState)> &functor, unsigned long stateMask, RWCallbackScope scope=RW_CALL_REPEATEDLY)
 
RWCompletionState getCompletionState () const
 
RWExecutionState getExecutionState () const
 
bool isInterruptRequested () const
 
bool isSelf () const
 
bool isSelf (const RWThreadId &id) const
 
void removeCallback (const RWTFunctor< void(const RWRunnable &, RWExecutionState)> &functor)
 
RWThreadId threadId () const
 
- Public Member Functions inherited from RWHandleBase
bool isValid (void) const
 
bool operator!= (const RWHandleBase &second) const
 
bool operator== (const RWHandleBase &second) const
 

Static Public Member Functions

static RWThreadFunction make ()
 
static RWThreadFunction make (const RWTFunctor< void()> &functor)
 
static RWThreadFunction make (const RWTFunctor< void()> &functor, const RWThreadAttribute &attr)
 
static RWThreadFunction make (const RWThreadAttribute &attr)
 
- Static Public Member Functions inherited from RWThread
static bool canGetMaxThreads ()
 
static bool canSuspendResume ()
 
static size_t getMaxThreads ()
 

Additional Inherited Members

- Protected Member Functions inherited from RWThread
 RWThread (RWThreadImp *threadImpP)
 
- Protected Member Functions inherited from RWRunnable
 RWRunnable (const RWRunnableSelf &second)
 
- Protected Member Functions inherited from RWRunnableHandle
 RWRunnableHandle ()
 
 RWRunnableHandle (const RWRunnableHandle &second)
 
 RWRunnableHandle (RWRunnableImp *runnableImpP)
 
 RWRunnableHandle (RWStaticCtor)
 
 ~RWRunnableHandle ()
 
RWRunnableHandleoperator= (const RWRunnableHandle &second)
 
- Protected Member Functions inherited from RWHandleBase
 RWHandleBase (const RWHandleBase &second)
 
 RWHandleBase (RWBodyBase *body)
 
 RWHandleBase (RWStaticCtor)
 
 RWHandleBase (void)
 
 ~RWHandleBase (void)
 
RWBodyBasebody (void) const
 
RWHandleBaseoperator= (const RWHandleBase &second)
 

Detailed Description

The RWThreadFunction class is a handle class for functor-based threaded runnable objects.

A runnable object provides the basic mechanisms used to create, control, and monitor the threads of execution within your application. Runnables are used to define the task or activity to be performed by a thread.

Each runnable object is reference-counted; a threaded runnable body instance keeps a count of the number of handles that currently reference it. A runnable object is deleted when the last handle that references the body is deleted.

A functor-based runnable accepts a functor object for execution. A functor is an object that encapsulates a function call. Each functor keeps a pointer to the function and copies of the argument values that are to be passed to the function. Invoking a functor produces a call to the function.

A functor-based runnable simply redefines the basic run() member to invoke a functor instance stored within the runnable. With this capability, you do not have to resort to sub-classing or other intrusive techniques to customize the execution behavior of a runnable. The functor-base runnables allow you to dynamically specify the functions you want to execute when a runnable is started.

RWThreadFunction is used to access a threaded runnable, which creates a new thread to execute the specified functor.

Example
#include <rw/thread/RWThreadFunction.h>
#include <rw/functor/RWTFunctor.h>
#include <rw/functor/rwBind.h>
void foo(int i) { std::cout << i << std::endl; }
int main() {
// Create an RWThreadFunction that calls foo.
// Create a functor directly, passing 11 as client data.
RWTFunctor<void()> functor = rwBind(foo, 11);
threadfunc.start(); // spawns a thread that prints 7
threadfunc.join();
// Set threadfunc to use the new functor:
threadfunc.setFunctor(functor);
threadfunc.start(); // spawns a thread that prints 11
threadfunc.join();
return 0;
}
RWCompletionState start()
void join(void)
Handle class for functor-based threaded runnable objects.
Definition RWThreadFunction.h:90
static RWThreadFunction make()
void setFunctor(const RWTFunctor< void()> &functor)
unspecified_type rwBind(C &&c, As &&... args)
Binds a callable and arguments into a callable object.
See also
RWTFunctor, RWThread, rwBind

Constructor & Destructor Documentation

◆ RWThreadFunction() [1/2]

RWThreadFunction::RWThreadFunction ( )
inline

Constructs an empty RWThreadFunction handle instance.

◆ RWThreadFunction() [2/2]

RWThreadFunction::RWThreadFunction ( const RWThreadFunction & second)
inline

Binds a new handle to the runnable instance, if any, pointed to by the handle second.

◆ ~RWThreadFunction()

RWThreadFunction::~RWThreadFunction ( )
inline

Destructor.

Member Function Documentation

◆ getFunctor()

RWTFunctor< void()> RWThreadFunction::getFunctor ( ) const

Gets the current functor instance, if any, associated with the runnable.

Possible exceptions include RWTHRInvalidPointer and RWTHRInternalError.

◆ make() [1/4]

static RWThreadFunction RWThreadFunction::make ( )
static

Constructs and returns an RWThreadFunction object with an undefined functor. The setFunctor() member must be used to define a functor prior to starting.

◆ make() [2/4]

static RWThreadFunction RWThreadFunction::make ( const RWTFunctor< void()> & functor)
static

Constructs and returns an RWRunnableFunction that executes the specified functor when started.

◆ make() [3/4]

static RWThreadFunction RWThreadFunction::make ( const RWTFunctor< void()> & functor,
const RWThreadAttribute & attr )
static

Constructs and returns an RWRunnableFunction that executes the specified functor when started. A new thread is created using the thread attributes given by attr.

◆ make() [4/4]

static RWThreadFunction RWThreadFunction::make ( const RWThreadAttribute & attr)
static

Constructs and returns an RWThreadFunction object with an undefined functor. The setFunctor() member must be used to define a function prior to starting. A new thread is created using the attributes given by attr.

◆ operator=()

RWThreadFunction & RWThreadFunction::operator= ( const RWThreadFunction & second)
inline

Binds this to the runnable instance, if any, pointed to by the handle second.

◆ setFunctor()

void RWThreadFunction::setFunctor ( const RWTFunctor< void()> & functor)

Sets the functor to be executed by this runnable.

Possible exceptions include RWTHRInvalidPointer and RWTHRInternalError.

Copyright © 2024 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.