Using Callbacks
Execution state callbacks are an asynchronous mechanism for reacting to execution state changes. Each time a runnable changes its execution state, it checks for and invokes any callbacks that have been registered for that particular execution state. Any callbacks associated with an execution state are invoked prior to releasing any threads waiting on that same execution state via the RWRunnable::wait() functions.
Callbacks are specified using functors. The functors used for callbacks are based on a different functor class family than those specified for execution within a runnable. These functors are passed the runnable and the current execution state when invoked. This allows the callback function to determine the source and state of each callback invocation. Any function that you create for use as an execution state callback can accept additional arguments and must accept the two values shown in Example 15 as its first two arguments.
Example 15 – Creating a function for an execution state callback
void myCallback(const RWRunnable& runnable,
RWExecutionState state)
{
// Do something useful
}
To use your function as a callback, construct a compatible functor instance that calls the function when invoked, as shown in Example 16.
Example 16 – Using a function as a callback
RWTFunctor<void(const RWRunnable&,RWExecutionState)> myFunctor;
myFunctor = myCallback;
For more information on using and constructing functors, see the Functor page accessible from the Modules tab of the SourcePro API Reference Guide.