libthreadar::condition Class Reference

Wrapper around the Posix pthread_cond_t object and its associated mutex. More...

`#include <condition.hpp>`

Inherits libthreadar::mutex.

## Public Member Functions

| condition (unsigned int num=1)
| constructor More...
| 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() More...
void | signal (unsigned int instance=0)
| awakes a single thread suspended after having called wait() More...
void | broadcast (unsigned int instance=0)
| awakes all threads suspended after having called wait() More...
unsigned int | get_waiting_thread_count (unsigned int instance=0)
| return the number of thread currently waiting on that condition More...
Public Member Functions inherited from libthreadar::mutex
| 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 More...
void | unlock ()
| unlock the mutex More...
bool | try_lock ()
| Tells whether calling lock() would currently suspend the caller or not. More...

## Additional Inherited Members

Protected Attributes inherited from libthreadar::mutex
pthread_mutex_t | mut

## Detailed Description

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.

## Constructor & Destructor Documentation

## 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

## Member Function Documentation

## 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:

- condition.hpp