SourcePro C++ 12.0 |
SourcePro® C++ API Reference Guide |
SourcePro C++ Documentation Home |
Waits for a number of runnables or threads to reach a certain execution state. More...
#include <rw/thread/RWRunnableTrap.h>
Public Member Functions | |
RWRunnableTrap () | |
RWRunnableTrap (RWStaticCtor) | |
RWRunnableTrap (const RWRunnableTrap &second) | |
~RWRunnableTrap () | |
RWRunnableTrap & | operator= (const RWRunnableTrap &second) |
bool | isEmpty (void) const |
void | setTrap (RWRunnable runnable, RWCallbackScope scope=RW_CALL_ONCE) |
RWRunnable | getNext () |
RWWaitStatus | getNext (RWRunnable &r, unsigned long milliseconds) |
void | getNext (RWRunnable &r, RWExecutionState &es) |
RWWaitStatus | getNext (RWRunnable &r, RWExecutionState &es, unsigned long milliseconds) |
bool | tryGetNext (RWRunnable &runnable) |
bool | tryGetNext (RWRunnable &runnable, RWExecutionState &es) |
Static Public Member Functions | |
static RWRunnableTrap | make (unsigned long executionStateMask=RW_THR_INITIAL) |
Protected Member Functions | |
RWRunnableTrap (RWRunnableTrapImp *runnableTrapImpP) | |
RWRunnableTrapImp & | body (void) const |
RWRunnableTrap allows you to wait for a number of runnables or threads to reach a certain execution state. When you create an RWRunnableTrap you specify the target execution state. This causes any runnable that the trap has been set on to catch the runnable when it reaches the given execution state.
Another thread can get each runnable as it reaches the target execution state by calling the getNext() function of the runnable trap. A runnable may be caught by the trap by calling setTrap() and passing in the target runnable. By default the runnable is caught only once, the first time that it enters the execution state. When you set the trap on a runnable you may specify that the runnable be caught repeatedly, each time that it enters the execution state.
A common usage of an RWRunnableTrap is to wait for a number of threads to complete execution. This allows you to launch and wait for multiple threads without having to keep track of those threads in an array or other data structure. After a thread is created, but before it is started, it can be added to a runnable trap.
The default target execution state is RW_THR_INITIAL which is the state that a runnable reaches when it completes execution.
#include <rw/thread/RWRunnableTrap.h> #include <rw/thread/RWRunnable.h> #include <rw/thread/RWThread.h> #include <rw/thread/rwtMakeThreadFunction.h> RWRunnableTrap rnblTrap = RWRunnableTrap::make(); int i; for (i= 0; i<10; i++) { RWThread thread = rwtMakeThreadFunction(function); rnblTrap.setTrap(thread); // before starting thread! thread.start(); } for (i=0; i<10; i++) { RWRunnable rnbl = rnblTrap.getNext(); rnbl.join(); }
RWRunnableTrap::RWRunnableTrap | ( | void | ) | [inline] |
Constructs an invalid RWRunnableTrap. If the runnable trap is used without having being initialized, an invalid pointer exception is thrown.
RWRunnableTrap::RWRunnableTrap | ( | RWStaticCtor | ) | [inline] |
Constructs a static RWRunnableTrap.
RWRunnableTrap::RWRunnableTrap | ( | const RWRunnableTrap & | second | ) | [inline] |
Copy constructor.
RWRunnableTrap::~RWRunnableTrap | ( | void | ) | [inline] |
Default destructor.
RWRunnableTrap::RWRunnableTrap | ( | RWRunnableTrapImp * | runnableTrapImpP | ) | [protected] |
Constructs a handle from an RWRunnableTrapImp*
.
RWRunnableTrapImp& RWRunnableTrap::body | ( | void | ) | const [protected] |
Gets a reference for the body instance, if any.
RWTHRInvalidPointer | Thrown if this handle is not attached to a body. |
Reimplemented from RWHandleBase.
RWWaitStatus RWRunnableTrap::getNext | ( | RWRunnable & | r, | |
RWExecutionState & | es, | |||
unsigned long | milliseconds | |||
) |
Gets the next trapped RWRunnable and the execution state that caused it to be trapped. Times out after given milliseconds if no RWRunnable is trapped. Returns either RW_THR_TIMEOUT or RW_THR_COMPLETED.
void RWRunnableTrap::getNext | ( | RWRunnable & | r, | |
RWExecutionState & | es | |||
) |
Gets the next trapped RWRunnable and the execution state that caused it to be trapped.
RWWaitStatus RWRunnableTrap::getNext | ( | RWRunnable & | r, | |
unsigned long | milliseconds | |||
) |
Gets the next RWRunnable that has entered RWExecutionState. Times out after given milliseconds if no RWRunnable is trapped. Returns either RW_THR_TIMEOUT or RW_THR_COMPLETED.
RWRunnable RWRunnableTrap::getNext | ( | ) |
Gets the next RWRunnable that has entered RWExecutionState. Blocks if no RWRunnable is trapped.
bool RWRunnableTrap::isEmpty | ( | void | ) | const |
Returns true
if the queue is empty, otherwise false
.
static RWRunnableTrap RWRunnableTrap::make | ( | unsigned long | executionStateMask = RW_THR_INITIAL |
) | [static] |
Constructs a runnable trap to catch runnables as they reach the given execution state(s). The default is to wait until a runnable finishes execution and returns to its initial state. (See RWExecutionState.)
RWRunnableTrap & RWRunnableTrap::operator= | ( | const RWRunnableTrap & | second | ) | [inline] |
Assignment operator.
void RWRunnableTrap::setTrap | ( | RWRunnable | runnable, | |
RWCallbackScope | scope = RW_CALL_ONCE | |||
) |
Traps the given runnable when it enters RWExecutionState (specified when the runnable trap was created.) An RWCallbackScope may be specified as either RW_CALL_ONCE or RW_CALL_REPEATEDLY. This determines whether the runnable should enter the trap only once when it enters the target execution state, or repeatedly, each time it enters that state.
bool RWRunnableTrap::tryGetNext | ( | RWRunnable & | runnable, | |
RWExecutionState & | es | |||
) |
Gets the next runnable to reach the target execution state, if one is available. Returns true
and sets the runnable parameter if one could be read, otherwise returns false
. Sets es to the execution state that tripped the trap.
bool RWRunnableTrap::tryGetNext | ( | RWRunnable & | runnable | ) |
Gets the next runnable to reach the target execution state, if one is available. Returns true
and sets the runnable parameter if one could be read, otherwise returns false
.
© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.