Wrapper around the Posix pthread_cond_t object and its associated mutex.
More...
#include <condition.hpp>
Inherits libthreadar::mutex.
|
| condition (unsigned int num=1) |
| constructor
|
|
| condition (const condition &ref)=delete |
| no copy constructor
|
|
| condition (condition &&ref)=default |
| no move constructor
|
|
condition & | operator= (const condition &ref)=delete |
| no assignment operator
|
|
condition & | operator= (condition &&ref) noexcept=default |
| no move operator
|
|
| ~condition () |
| destructor
|
|
void | wait (unsigned int instance=0) |
| put the calling thread on hold waiting for another thread to call signal()
|
|
void | signal (unsigned int instance=0) |
| awakes a single thread suspended after having called wait()
|
|
void | broadcast (unsigned int instance=0) |
| awakes all threads suspended after having called wait()
|
|
unsigned int | get_waiting_thread_count (unsigned int instance=0) |
| return the number of thread currently waiting on that condition
|
|
| mutex () |
| constructor
|
|
| mutex (const mutex &ref)=delete |
| no copy constructor
|
|
| mutex (mutex &&ref)=default |
| no move constructor
|
|
mutex & | operator= (const mutex &ref)=delete |
| no assignment operator
|
|
mutex & | operator= (mutex &&ref) noexcept=default |
| no move operator
|
|
virtual | ~mutex () |
| destructor
|
|
void | lock () |
| lock the mutex
|
|
void | unlock () |
| unlock the mutex
|
|
bool | try_lock () |
| Tells whether calling lock() would currently suspend the caller or not.
|
|
Wrapper around the Posix pthread_cond_t object and its associated mutex.
- Note
- each object share a user defined set of condition on the same mutex as defined at constructor time. wait() takes as argument the condition number and will be awaken by a signal() or broadcast() having this same number as argument
Definition at line 45 of file condition.hpp.
◆ condition()
libthreadar::condition::condition |
( |
unsigned int |
num = 1 | ) |
|
constructor
- Parameters
-
[in] | num | number of instance to create, each instance is a separated condition relying on the same mutex. First instance starts with index 0 |
◆ broadcast()
void libthreadar::condition::broadcast |
( |
unsigned int |
instance = 0 | ) |
|
awakes all threads suspended after having called wait()
- Parameters
-
[in] | instance | broadcast threads that have been waiting on that instance |
- Note
- broadcast() must be called between lock() and unlock(). This is only at the time unlock() is called that another thread exits from the suspended state.
◆ get_waiting_thread_count()
unsigned int libthreadar::condition::get_waiting_thread_count |
( |
unsigned int |
instance = 0 | ) |
|
|
inline |
return the number of thread currently waiting on that condition
- Parameters
-
[in] | instance | the condition instance number to count the waiting thread on |
Definition at line 98 of file condition.hpp.
◆ signal()
void libthreadar::condition::signal |
( |
unsigned int |
instance = 0 | ) |
|
awakes a single thread suspended after having called wait()
- Parameters
-
[in] | instance | signal thread that have been waiting on that instance |
- Note
- signal() must be called between lock() and unlock(). This is only at the time unlock() is called that another thread exits from the suspended state.
◆ wait()
void libthreadar::condition::wait |
( |
unsigned int |
instance = 0 | ) |
|
put the calling thread on hold waiting for another thread to call signal()
- Parameters
-
[in] | instance | the instance number to have the caller waiting on |
- Note
- wait() must be called between lock() and unlock(). Once suspendend, the calling thread unlocks the mutex and acquires the mutex lock() again once awaken after another thread called signal
The documentation for this class was generated from the following file: