SourcePro® API Reference Guide

Product Documentation:
   SourcePro
Documentation Home
List of all members | Public Member Functions | Static Public Member Functions
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 (RWStaticCtor)
 
 RWThread (const RWThread &second)
 
 ~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 (RWStaticCtor)
 
 RWRunnable (const RWRunnable &second)
 
 ~RWRunnable ()
 
RWRunnable getNestedRunnable () const
 
RWRunnableSelf getRWRunnableSelf () const
 
void join (void)
 
RWWaitStatus join (unsigned long milliseconds)
 
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
 
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 (RWStaticCtor)
 
 RWRunnableHandle (RWRunnableImp *runnableImpP)
 
 RWRunnableHandle (const RWRunnableHandle &second)
 
 ~RWRunnableHandle ()
 
RWRunnableHandleoperator= (const RWRunnableHandle &second)
 
- Protected Member Functions inherited from RWHandleBase
 RWHandleBase (void)
 
 RWHandleBase (RWStaticCtor)
 
 RWHandleBase (RWBodyBase *body)
 
 RWHandleBase (const RWHandleBase &second)
 
 ~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/rwBind.h>
#include <rw/functor/RWTFunctor.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;
}
See also
RWTFunctor, RWThread, rwBind

Constructor & Destructor Documentation

RWThreadFunction::RWThreadFunction ( )
inline

Constructs an empty RWThreadFunction handle instance.

RWThreadFunction::RWThreadFunction ( const RWThreadFunction second)
inline

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

RWThreadFunction::~RWThreadFunction ( )
inline

Destructor.

Member Function Documentation

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

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

Possible exceptions include RWTHRInvalidPointer and RWTHRInternalError.

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.

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

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

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.

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.

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

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

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

Sets the functor to be executed by this runnable.

Possible exceptions include RWTHRInvalidPointer and RWTHRInternalError.

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