SourcePro® API Reference Guide

 
List of all members | Public Member Functions | Static Public Member Functions
RWRunnableFunction Class Reference

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

#include <rw/thread/RWRunnableFunction.h>

Inheritance diagram for RWRunnableFunction:
RWRunnable RWRunnableHandle RWHandleBase

Public Member Functions

 RWRunnableFunction ()
 
 RWRunnableFunction (RWStaticCtor)
 
 RWRunnableFunction (const RWRunnableFunction &second)
 
 ~RWRunnableFunction ()
 
RWTFunctor< void()> getFunctor () const
 
RWRunnableFunctionoperator= (const RWRunnableFunction &second)
 
void setFunctor (const RWTFunctor< void()> &functor)
 
- 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 RWRunnableFunction make ()
 
static RWRunnableFunction make (const RWTFunctor< void()> &functor)
 

Additional Inherited Members

- 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 RWRunnableFunction class is a handle class for functor-based 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 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 used to encapsulate 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-based runnables allow you to dynamically specify the functions you want to execute when a runnable is started.

RWRunnableFunction is used to access a synchronous runnable, which executes the specified functor in the same thread that calls start().

Example
#include <rw/functor/rwBind.h>
#include <rw/functor/RWTFunctor.h>
#include <rw/thread/RWRunnableFunction.h>
void foo(int i)
{
std::cout << i << std::endl;
}
int main()
{
// Create an RWRunnableFunction that calls foo.
RWRunnableFunction runnablefunc =
runnablefunc.start(); // prints 7
// Create a functor directly, passing 11 as client data.
RWTFunctor<void()> functor = rwBind(foo, 11);
// Set runnablefunc to use the new functor:
runnablefunc.setFunctor(functor);
runnablefunc.start(); // prints 11
return 0;
}

Constructor & Destructor Documentation

RWRunnableFunction::RWRunnableFunction ( )
inline

Constructs an empty RWRunnableFunction handle instance.

RWRunnableFunction::RWRunnableFunction ( RWStaticCtor  )
inline

Constructs a global static handle instance that may be assigned to before construction. The static constructor does not change the instance state.

RWRunnableFunction::RWRunnableFunction ( const RWRunnableFunction second)
inline

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

RWRunnableFunction::~RWRunnableFunction ( )
inline

Destructor.

Member Function Documentation

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

Gets the current functor instance, if any, associated with the runnable. Possible exceptions include RWTHRInvalidPointer and RWTHRInternalError.

static RWRunnableFunction RWRunnableFunction::make ( )
static

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

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

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

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

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

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

Sets the functor to be executed by this runnable. Possible exceptions include RWTHRInvalidPointer and RWTHRInternalError.

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