Implementation of a condition variable.
More...
#include <PosixCondition.hpp>
Public Member Functions |
| PosixCondition () |
| Constructor. Initialize the condition variable.
|
| ~PosixCondition () |
| Destructor. Destroys the condition variable.
|
int | wait (PosixMutex *m) |
| Blocks the calling thread on the condition variable.
|
int | timedWait (PosixMutex *m, const Time &abstime) |
| Blocks the calling thread on the condition variable.
|
int | signal () |
| Unblocks at least one of the blocked threads.
|
int | signalAll () |
| Unblocks all blocked threads.
|
Private Attributes |
pthread_cond_t | cond_ |
Detailed Description
Implementation of a condition variable.
The class is non copyable and makes use of the pthread library.
Definition at line 38 of file PosixCondition.hpp.
Constructor & Destructor Documentation
Constructor. Initialize the condition variable.
- Exceptions
-
runtime_error | if the initialization of the condition variable fails. |
Definition at line 35 of file PosixCondition.cpp.
{
if (pthread_cond_init(&
cond_, NULL) != 0)
throw std::runtime_error(std::string("Error: ") + strerror(errno));
}
Member Function Documentation
Unblocks at least one of the blocked threads.
- Returns
- 0 in case of success
Definition at line 82 of file PosixCondition.hpp.
{
return pthread_cond_signal(&
cond_);
}
Unblocks all blocked threads.
- Returns
- 0 in case of success
Definition at line 91 of file PosixCondition.hpp.
{
return pthread_cond_broadcast(&
cond_);
}
Blocks the calling thread on the condition variable.
These functions atomically release mutex and cause the calling thread to block on the condition variable.
- Parameters
-
m | Mutex released when blocking and acquired when unblocking. |
abstime | Absolute time for timeout |
- Returns
- 0 in case of success, ETIMEDOUT in case of timeout
Definition at line 70 of file PosixCondition.hpp.
{
timespec ts;
ts.tv_sec = abstime.getSeconds();
ts.tv_nsec = abstime.getNSeconds();
return pthread_cond_timedwait(&
cond_, &(m->mutex_), &ts);
}
Blocks the calling thread on the condition variable.
These functions atomically release mutex and cause the calling thread to block on the condition variable.
- Parameters
-
m | Mutex released when blocking and acquired when unblocking. |
- Returns
- 0 in case of success
Definition at line 57 of file PosixCondition.hpp.
{
return pthread_cond_wait(&
cond_, &(m->mutex_));
}
Member Data Documentation
The documentation for this class was generated from the following files: