#include <wefts_cond.h>
Inheritance diagram for Wefts::Condition:
Public Methods | |
Condition (Mutex *mtx=0) | |
Initializes the internal data of the condition. | |
~Condition () | |
virtual bool | wait () |
Waits for the condition to be active. | |
void | setMutex (Mutex *mtx) |
virtual bool | wait (long seconds, long nanoseconds) |
Waits for the condition to be active up to a certain time. | |
int | wait (double seconds) |
Waits for the condition to be active for a certain time. | |
virtual void | signal () |
Signals the condition. | |
void | onStop (CleanupHandler *guard=0, int param=0) |
Set up cancelation handler. | |
Protected Attributes | |
OSCondition | m_cond |
Internal condition variable. | |
Mutex * | m_my_mutex |
Internal mutex. | |
CleanupItem | m_whenStopped |
This condition class is meant to be overloaded by classes using specific mutex types. To use it, you have to create your own class using a combination of this class plus a fast or a reentrant mutex. This is implemented in the wtFastCondition and wtRCondition classes.
Subclassess must set m_my_mutex to a valid Wefts::Mutex pointer (or any subclass of that).
All condition classes are implemented via inline calls to maximize execution speed; also, their metods are extremely small.
|
Initializes the internal data of the condition. Initialization of m_my_mutex member is left to subclasses. |
|
|
|
Set up cancelation handler. When a thread waiting on a condition is canceled the thread cleanup system is called with the condition in locked() status. It is necessary to unlock it before to proceed; so it is necessary to provide a CleanupHandler. If you have access to the calling thread you can use Thread::pushCleanup(), while if you have not access to it you should use this method (that is anyhow more efficient).
|
|
|
|
Signals the condition. When a condition is signaled all the waiting threads are given a chance to go. |
|
Waits for the condition to be active for a certain time. Works as wait( long seconds, long nanoseconds), but the wait time can be expressed as a real number, 1.0 meaning a second. Be sure to 1) don't stop a thread while waiting on a condition, 2) disable cancelation around a wait() or 3) set up a cancelation sequence (Condition cleanup).
|
|
Waits for the condition to be active up to a certain time. This method works as wait() but returns (with nonzero value) if a certain time has elapsed. If you call this function, you have to specify the amount of seconds and second fractions (expressed in nanoseconds) you want to wait for a single event to be risen. Granularity of the system greatly depends on underlying OS and process priviledges. Be sure to 1) don't stop a thread while waiting on a condition, 2) disable cancelation around a wait() or 3) set up a cancelation sequence (Condition cleanup).
|
|
Waits for the condition to be active. This method waits forever or until stopped by an external event (signal). Be sure to 1) don't stop a thread while waiting on a condition, 2) disable cancelation around a wait() or 3) set up a cancelation sequence (Condition cleanup).
|
|
Internal condition variable.
|
|
Internal mutex. Subclasses are invited to set this mutex to an initialized specific kind of mutex at creation. |
|
|