#include <wefts_cond.h>
Inheritance diagram for Wefts::Condition:
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.
Public Member Functions | |
Condition (Mutex *mtx=0) | |
Initializes the internal data of the condition. | |
~Condition () | |
virtual bool | wait (CleanupHandler *cup=0, int pos=0) |
Waits for the condition to be active. | |
void | setMutex (Mutex *mtx) |
Set the mutex used by this condition. | |
Mutex * | getMutex () |
virtual bool | wait (long seconds, long nanoseconds, CleanupHandler *cup=0, int pos=0) |
Waits for the condition to be active up to a certain time. | |
bool | wait (double seconds, CleanupHandler *cup=0, int pos=0) |
Waits for the condition to be active for a certain time. | |
virtual void | signal () |
Signals the condition, waking all waiting threads. | |
virtual void | signalOne () |
Signals the condition, waking one thread. | |
Protected Attributes | |
OSCondition | m_cond |
Internal condition variable. | |
Mutex * | m_my_mutex |
Internal mutex. |
|
Initializes the internal data of the condition. Initialization of m_my_mutex member is left to subclasses. |
|
|
|
|
|
Set the mutex used by this condition. Usually, this is used by subclasses, dervied both by conditionts and mutexes to set themselves as mutexes. It may also be used in 1:N mutexing schemes, where a single mutex (protecting a wide dataset) must be used by more than one condition (each willing to test part of that dataset). |
|
Signals the condition, waking all waiting threads. When a condition is signaled all the waiting threads are given a chance to go. |
|
Signals the condition, waking one thread. When a condition is signaled with this method, only one of the wating threads are awaken. This is only useful in situation where it can be prooved that
|
|
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 cancellation around a wait() or 3) set up a cancellation 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 cancellation around a wait() or 3) set up a cancellation 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 cancellation around a wait() or 3) set up a cancellation sequence (Condition cleanup).
|
|
Internal condition variable.
|
|
Internal mutex. Subclasses are invited to set this mutex to an initialized specific kind of mutex at creation. |