Condition for threads. More...
#include <Radiant/Condition.hpp>
Public Member Functions | |
| Condition () | |
| Constructor. | |
| bool | wait (Mutex &mutex, unsigned long millisecs=std::numeric_limits< unsigned long >::max()) |
| Waits on the wait condition for at most the given time. More... | |
| bool | wait2 (Mutex &mutex, unsigned int &timeoutMs) |
| Waits on the wait condition for at most the given time. More... | |
| void | wakeAll () |
| Wakes all threads waiting on the condition. | |
| void | wakeAll (Mutex &mutex) |
| Wakes all threads waiting on the condition, while locking the given mutx. More... | |
| void | wakeOne () |
| Wakes one thread waiting on the condition (the woken thread can not be controlled or predicted) | |
| void | wakeOne (Mutex &mutex) |
| Wakes one thread waiting on the condition (the woken thread can not be controlled or predicted) while locking the given mutex. More... | |
| ~Condition () | |
| Destructor. | |
Condition for threads.
Typical use pattern for thread that waits:
mutex.lock();
while(needMoreData()) condition.wait(mutex);
mutex.unlock();
Typical use pattern for thread that informs its children:
mutex.lock(); condition.wakeAll(); mutex.unlock();
Or simply:
condition.wakeAll(mutex);
| bool Radiant::Condition::wait | ( | Mutex & | mutex, |
| unsigned long | millisecs = std::numeric_limits< unsigned long >::max() |
||
| ) |
Waits on the wait condition for at most the given time.
The mutex must be locked by the calling thread. The mutex is released. If the mutex is not locked the function will return immediately.
| mutex | locked mutex |
| millisecs | timeout in milliseconds |
| bool Radiant::Condition::wait2 | ( | Mutex & | mutex, |
| unsigned int & | timeoutMs | ||
| ) |
Waits on the wait condition for at most the given time.
Decreases the parameter timeoutMs by amount of time waited. If the wait is timed out returns false; otherwise true.
| mutex | locked mutex | |
| [in,out] | timeoutMs | timeout in milliseconds to wait |
| void Radiant::Condition::wakeAll | ( | Mutex & | mutex | ) |
Wakes all threads waiting on the condition, while locking the given mutx.
| mutex | Mutex to lock |