Condition variable. More...
#include <paraPthCondVar.h>
Public Member Functions | |
ConditionVariable (Lock *l=0) | |
Create a new condition variable. If l is NULL then the constructor will create a new Lock instance and will associate this with the newly created condition variable. The Lock instance will be destroyed in the destructor. If l is not NULL then the constructor will associate the newly created condition variable with l (the destructor will not delete l). More... | |
~ConditionVariable () | |
Destroy this condition variable. If the constructor allocated a new Lock for this condition variable then this Lock is also destroyed. More... | |
void | setLock (Lock *l) |
set Lock from outside. More... | |
void | lock () |
Acquire the lock associated with this condition variable. More... | |
void | lock (char const *file, int line) |
Acquire the lock associated with this condition variable. More... | |
void | unlock () |
Release the lock associated with this condition variable. More... | |
void | wait () |
Wait for this condition variable. The calling thread MUST hold the lock associated with this condition variable when calling this function. More... | |
void | signal () |
Signal this condition variable. Signalling a condition variable will wake up ONE thread that is currently waiting on the variable. More... | |
void | broadcast () |
Signal on this condition variable. Broadcasting on a condition variable will wake up ALL threads that are currently waiting on the variable. More... | |
Lock * | getLock () const |
Get the lock associated with this condition variable. More... | |
Private Member Functions | |
ConditionVariable (ConditionVariable const &) | |
No copying or assignment of condition variables. More... | |
ConditionVariable & | operator= (ConditionVariable const &) |
Private Attributes | |
Lock * | lck |
The lock associated with this instance. More... | |
bool | ownMutex |
This is true iff the constructor did allocate lck. More... | |
pthread_cond_t | cond |
The low-level condition variable. More... | |
Condition variable.
This class wraps around pthread_cond_t. A condition variable is always associated with a mutex (which must be held when the condition controlled by the condition variable is modified). There are two ways to associate a mutex (an instance of Lock) with a condition variable:
Definition at line 58 of file paraPthCondVar.h.
|
private |
No copying or assignment of condition variables.
ConditionVariable | ( | Lock * | l = 0 | ) |
Create a new condition variable. If l is NULL then the constructor will create a new Lock instance and will associate this with the newly created condition variable. The Lock instance will be destroyed in the destructor. If l is not NULL then the constructor will associate the newly created condition variable with l (the destructor will not delete l).
Definition at line 78 of file paraPthCondVar.h.
References ConditionVariable::cond, ConditionVariable::lck, and ConditionVariable::ownMutex.
~ConditionVariable | ( | ) |
Destroy this condition variable. If the constructor allocated a new Lock for this condition variable then this Lock is also destroyed.
Definition at line 99 of file paraPthCondVar.h.
References ConditionVariable::cond, ConditionVariable::lck, and ConditionVariable::ownMutex.
void broadcast | ( | ) |
Signal on this condition variable. Broadcasting on a condition variable will wake up ALL threads that are currently waiting on the variable.
Definition at line 176 of file paraPthCondVar.h.
References ConditionVariable::cond.
Lock * getLock | ( | ) | const |
Get the lock associated with this condition variable.
Definition at line 188 of file paraPthCondVar.h.
References ConditionVariable::lck.
void lock | ( | ) |
Acquire the lock associated with this condition variable.
Definition at line 122 of file paraPthCondVar.h.
References ConditionVariable::lck, and Lock::lock().
void lock | ( | char const * | file, |
int | line | ||
) |
Acquire the lock associated with this condition variable.
file | file name |
line | line number |
Definition at line 131 of file paraPthCondVar.h.
References ConditionVariable::lck, and Lock::lock().
|
private |
void setLock | ( | Lock * | l | ) |
set Lock from outside.
l | lock |
Definition at line 110 of file paraPthCondVar.h.
References ConditionVariable::lck, and ConditionVariable::ownMutex.
Referenced by ParaCommPth::init().
void signal | ( | ) |
Signal this condition variable. Signalling a condition variable will wake up ONE thread that is currently waiting on the variable.
Definition at line 163 of file paraPthCondVar.h.
References ConditionVariable::cond.
void unlock | ( | ) |
Release the lock associated with this condition variable.
Definition at line 142 of file paraPthCondVar.h.
References ConditionVariable::lck, and Lock::unlock().
void wait | ( | ) |
Wait for this condition variable. The calling thread MUST hold the lock associated with this condition variable when calling this function.
Definition at line 149 of file paraPthCondVar.h.
References ConditionVariable::cond, ConditionVariable::lck, and Lock::mtx.
|
private |
The low-level condition variable.
Definition at line 62 of file paraPthCondVar.h.
Referenced by ConditionVariable::broadcast(), ConditionVariable::ConditionVariable(), ConditionVariable::signal(), ConditionVariable::wait(), and ConditionVariable::~ConditionVariable().
|
private |
The lock associated with this instance.
Definition at line 60 of file paraPthCondVar.h.
Referenced by ConditionVariable::ConditionVariable(), ConditionVariable::getLock(), ConditionVariable::lock(), ConditionVariable::setLock(), ConditionVariable::unlock(), ConditionVariable::wait(), and ConditionVariable::~ConditionVariable().
|
private |
This is true iff the constructor did allocate lck.
Definition at line 61 of file paraPthCondVar.h.
Referenced by ConditionVariable::ConditionVariable(), ConditionVariable::setLock(), and ConditionVariable::~ConditionVariable().