![]() |
![]() |
Public Member Functions | |
Cond () | |
~Cond () | |
void | signal () |
If threads are waiting for this Cond, exactly one of them is woken up. | |
void | broadcast () |
If threads are waiting for this Cond, all of them are woken up. | |
void | wait (Mutex& mutex) |
Waits until this thread is woken up on this Cond. | |
bool | timed_wait (Mutex& mutex, const Glib::TimeVal& abs_time) |
Waits until this thread is woken up on this Cond, but not longer than until the time, that is specified by abs_time. | |
GCond* | gobj () |
A Cond is an object that threads can block on, if they find a certain condition to be false. If other threads change the state of this condition they can signal the Cond, such that the waiting thread is woken up.
Glib::Cond data_cond; Glib::Mutex data_mutex; void* current_data = NULL; void push_data (void* data) { data_mutex.lock(); current_data = data; data_cond.signal(); data_mutex.unlock(); } void* pop_data () { void* data; data_mutex.lock(); while (!current_data) data_cond.wait(data_mutex); data = current_data; current_data = NULL; data_mutex.unlock(); return data; }
Glib::Cond::Cond | ( | ) |
Glib::Cond::~Cond | ( | ) |
void Glib::Cond::signal | ( | ) |
If threads are waiting for this Cond, exactly one of them is woken up.
It is good practice to hold the same lock as the waiting thread, while calling this method, though not required.
void Glib::Cond::broadcast | ( | ) |
If threads are waiting for this Cond, all of them are woken up.
It is good practice to hold the same lock as the waiting thread, while calling this method, though not required.
void Glib::Cond::wait | ( | Mutex& | mutex | ) |
Waits until this thread is woken up on this Cond.
The mutex is unlocked before falling asleep and locked again before resuming.
This method can also be used if Glib::thread_init() has not yet been called and will immediately return then.
mutex | a Mutex that is currently locked. |
bool Glib::Cond::timed_wait | ( | Mutex& | mutex, | |
const Glib::TimeVal& | abs_time | |||
) |
Waits until this thread is woken up on this Cond, but not longer than until the time, that is specified by abs_time.
The mutex is unlocked before falling asleep and locked again before resuming.
This function can also be used, if Glib::thread_init() has not yet been called and will immediately return true
then.
mutex | a Mutex that is currently locked. | |
abs_time | a max time to wait. |
GCond* Glib::Cond::gobj | ( | ) | [inline] |