Bayonne2 / Common C++ 2 Framework
Public Member Functions | Private Attributes
Conditional Class Reference

A conditional variable synchcronization object for one to one and one to many signal and control events between processes. More...

#include <thread.h>

Inheritance diagram for Conditional:
Inheritance graph
[legend]
Collaboration diagram for Conditional:
Collaboration graph
[legend]

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
 

Detailed Description

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.

Warning
While this class inherits from Mutex, the methods of the class Conditional just handle the system conditional variable, so the user is responsible for calling enterMutex and leaveMutex so as to avoid race conditions. Another thing to note is that if you have several threads waiting on one condition, not uncommon in thread pools, each thread must take care to manually unlock the mutex if cancellation occurs. Otherwise the first thread cancelled will deadlock the rest of the thread.
Author
David Sugar conditional.
Todo:
implement in win32

Definition at line 636 of file thread.h.

Constructor & Destructor Documentation

Conditional::Conditional ( const char *  id = NULL )

Create an instance of a conditional.

Parameters
id name of conditional, optional for deadlock testing.
virtual Conditional::~Conditional ( )
virtual

Destroy the conditional.

Member Function Documentation

void Conditional::enterMutex ( void  )

Locks the conditional's mutex for this thread.

Remember that Conditional's mutex is NOT a recursive mutex!

See Also
leaveMutex
void Conditional::leaveMutex ( void  )

Leaving a mutex frees that mutex for use by another thread.

See Also
enterMutex
void Conditional::lock ( void  )
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.

See Also
enterMutex

Definition at line 686 of file thread.h.

void Conditional::signal ( bool  broadcast )

Signal a conditional object and a waiting threads.

Parameters
broadcast this signal to all waiting threads if true.
bool Conditional::test ( void  )
inline

Definition at line 701 of file thread.h.

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.

Returns
true if locking the mutex was succesful otherwise false
See Also
enterMutex
leaveMutex
void Conditional::unlock ( void  )
inline

Definition at line 711 of file thread.h.

bool Conditional::wait ( timeout_t  timer = 0,
bool  locked = false 
)

Wait to be signaled from another thread.

Parameters
timer time period to wait.
locked flag if already locked the mutex.

Field Documentation

pthread_cond_t Conditional::_cond
private

Definition at line 639 of file thread.h.

pthread_mutex_t Conditional::_mutex
private

Definition at line 640 of file thread.h.


The documentation for this class was generated from the following file:

Generated on Dec 21, 2017 for commoncpp2-1.8.1, ccrtp-1.7.2, libzrtpcpp-2.3.4, ccscript3-1.1.7, ccaudio2-1.0.0 and bayonne2-2.3.2 (after installation in /usr/local/) by   doxygen 1.8.6

AltStyle によって変換されたページ (->オリジナル) /