SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches
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 (const RWRunnableFunction &second)
 
 RWRunnableFunction (RWStaticCtor)
 
 ~RWRunnableFunction ()
 
RWTFunctor< void()> getFunctor () const
 
RWRunnableFunctionoperator= (const RWRunnableFunction &second)
 
void setFunctor (const RWTFunctor< void()> &functor)
 
- 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 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 (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 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/thread/RWRunnableFunction.h>
#include <rw/functor/RWTFunctor.h>
#include <rw/functor/rwBind.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;
}
Handle class for functor-based, runnable objects.
Definition RWRunnableFunction.h:86
static RWRunnableFunction make()
void setFunctor(const RWTFunctor< void()> &functor)
RWCompletionState start()
unspecified_type rwBind(C &&c, As &&... args)
Binds a callable and arguments into a callable object.

Constructor & Destructor Documentation

◆ RWRunnableFunction() [1/3]

RWRunnableFunction::RWRunnableFunction ( )
inline

Constructs an empty RWRunnableFunction handle instance.

◆ RWRunnableFunction() [2/3]

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() [3/3]

RWRunnableFunction::RWRunnableFunction ( const RWRunnableFunction & second)
inline

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

◆ ~RWRunnableFunction()

RWRunnableFunction::~RWRunnableFunction ( )
inline

Destructor.

Member Function Documentation

◆ getFunctor()

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

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

◆ make() [1/2]

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.

◆ make() [2/2]

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

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

◆ operator=()

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

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

◆ setFunctor()

void RWRunnableFunction::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.