Implementation of the synchronization condition design pattern. More...
Classes | |
class | ConditionError |
Fatal low-level condition/threading error. More... | |
Public Member Functions | |
Condition () | |
Default constructor. More... | |
virtual | ~Condition () |
Destructor. | |
void | signal () |
Signal the condition. More... | |
bool | wait (Mutex &mutex, MilliSecond timeout) |
Wait for the condition to be signaled with a timeout and loose error reporting. More... | |
bool | wait (Mutex &mutex, MilliSecond timeout, bool &signaled) |
Wait for the condition to be signaled with a timeout,. More... | |
Implementation of the synchronization condition design pattern.
A condition is a general synchronization mechanism which is associated with a mutex.
Typical usage: A set of shared data is protected using a mutex (ts::Mutex). When some expected modification is performed, the modifier thread signals the condition. When other threads wait for the modification to be performed, they acquire the mutex and wait for the condition.
The implementation of this class is operating system dependent, just like ts::Thread and ts::Mutex.
ts::Condition::Condition | ( | ) |
Default constructor.
ts::Condition::ConditionError | In case of operating system error, when the underlying system objects could not be created. |
void ts::Condition::signal | ( | ) |
Signal the condition.
If more than one thread wait for the condition, at least one is awaken. It is then the responsibility of the awaken threads to check that the expected situation actually exists.
ts::Condition::ConditionError | In case of operating system error. |
bool ts::Condition::wait | ( | Mutex & | mutex, |
MilliSecond | timeout, | ||
bool & | signaled | ||
) |
Wait for the condition to be signaled with a timeout,.
The calling thread must have acquired the mutex first. The mutex is automatically released while waiting and then automatically re-acquired before returning with a successful status.
[in,out] | mutex | The mutex to automatically release/acquire. |
[in] | timeout | Maximum number of milliseconds to wait for the mutex. |
[out] | signaled | Set to true if the condition was successfully signaled and the timeout did not expired. |
|
inline |
Wait for the condition to be signaled with a timeout and loose error reporting.
The calling thread must have acquired the mutex first. The mutex is automatically released while waiting and then automatically re-acquired before returning with a successful status.
[in,out] | mutex | The mutex to automatically release/acquire. |
[in] | timeout | Maximum number of milliseconds to wait for the mutex. |