Bayonne2 / Common C++ 2 Framework
|
A conditional variable synchcronization object for one to one and one to many signal and control events between processes. More...
#include <thread.h>
Public Member Functions | |
Conditional (const char *id=NULL) | |
Create an instance of a conditional. More... | |
virtual | ~Conditional () |
Destroy the conditional. More... | |
void | signal (bool broadcast) |
Signal a conditional object and a waiting threads. More... | |
bool | wait (timeout_t timer=0, bool locked=false) |
Wait to be signaled from another thread. More... | |
void | enterMutex (void) |
Locks the conditional's mutex for this thread. More... | |
void | lock (void) |
In the future we will use lock in place of enterMutex since the conditional composite is not a recursive mutex, and hence using enterMutex may cause confusion in expectation with the behavior of the Mutex class. More... | |
bool | tryEnterMutex (void) |
Tries to lock the conditional for the current thread. More... | |
bool | test (void) |
void | leaveMutex (void) |
Leaving a mutex frees that mutex for use by another thread. More... | |
void | unlock (void) |
Private Attributes | |
pthread_cond_t | _cond |
pthread_mutex_t | _mutex |
A conditional variable synchcronization object for one to one and one to many signal and control events between processes.
Conditional variables may wait for and receive signals to notify when to resume or perform operations. Multiple waiting threads may be woken with a broadcast signal.
Conditional::Conditional | ( | const char * | id = NULL | ) |
Create an instance of a conditional.
id | name of conditional, optional for deadlock testing. |
|
virtual |
Destroy the conditional.
void Conditional::enterMutex | ( | void | ) |
Locks the conditional's mutex for this thread.
Remember that Conditional's mutex is NOT a recursive mutex!
void Conditional::leaveMutex | ( | void | ) |
Leaving a mutex frees that mutex for use by another thread.
|
inline |
In the future we will use lock in place of enterMutex since the conditional composite is not a recursive mutex, and hence using enterMutex may cause confusion in expectation with the behavior of the Mutex class.
void Conditional::signal | ( | bool | broadcast | ) |
Signal a conditional object and a waiting threads.
broadcast | this signal to all waiting threads if true. |
bool Conditional::tryEnterMutex | ( | void | ) |
Tries to lock the conditional for the current thread.
Behaves like enterMutex , except that it doesn't block the calling thread.
bool Conditional::wait | ( | timeout_t | timer = 0 , |
bool | locked = false |
||
) |
Wait to be signaled from another thread.
timer | time period to wait. |
locked | flag if already locked the mutex. |