Scippy

UG

Ubiquity Generator framework

ConditionVariable Class Reference

Condition variable. More...

#include <paraPthCondVar.h>

Public Member Functions

 ConditionVariable (Lock *l=0)
 Create a new condition variable. If l is NULL then the constructor will create a new Lock instance and will associate this with the newly created condition variable. The Lock instance will be destroyed in the destructor. If l is not NULL then the constructor will associate the newly created condition variable with l (the destructor will not delete l). More...
 
 ~ConditionVariable ()
 Destroy this condition variable. If the constructor allocated a new Lock for this condition variable then this Lock is also destroyed. More...
 
void setLock (Lock *l)
 set Lock from outside. More...
 
void lock ()
 Acquire the lock associated with this condition variable. More...
 
void lock (char const *file, int line)
 Acquire the lock associated with this condition variable. More...
 
void unlock ()
 Release the lock associated with this condition variable. More...
 
void wait ()
 Wait for this condition variable. The calling thread MUST hold the lock associated with this condition variable when calling this function. More...
 
void signal ()
 Signal this condition variable. Signalling a condition variable will wake up ONE thread that is currently waiting on the variable. More...
 
void broadcast ()
 Signal on this condition variable. Broadcasting on a condition variable will wake up ALL threads that are currently waiting on the variable. More...
 
LockgetLock () const
 Get the lock associated with this condition variable. More...
 

Private Member Functions

 ConditionVariable (ConditionVariable const &)
 No copying or assignment of condition variables. More...
 
ConditionVariableoperator= (ConditionVariable const &)
 

Private Attributes

Locklck
 The lock associated with this instance. More...
 
bool ownMutex
 This is true iff the constructor did allocate lck. More...
 
pthread_cond_t cond
 The low-level condition variable. More...
 

Detailed Description

Condition variable.

This class wraps around pthread_cond_t. A condition variable is always associated with a mutex (which must be held when the condition controlled by the condition variable is modified). There are two ways to associate a mutex (an instance of Lock) with a condition variable:

  1. Create the Lock instance and provide a pointer to it to the ConditionVariable constructor.
  2. Provide a NULL pointer to the ConditionVariable constructor. In that case the constructor will allocate a new Lock instance (and the destructor will destroy that lock).

Definition at line 58 of file paraPthCondVar.h.

Constructor & Destructor Documentation

◆ ConditionVariable() [1/2]

ConditionVariable ( ConditionVariable const &  )
private

No copying or assignment of condition variables.

◆ ConditionVariable() [2/2]

ConditionVariable ( Lock l = 0)

Create a new condition variable. If l is NULL then the constructor will create a new Lock instance and will associate this with the newly created condition variable. The Lock instance will be destroyed in the destructor. If l is not NULL then the constructor will associate the newly created condition variable with l (the destructor will not delete l).

Definition at line 78 of file paraPthCondVar.h.

References ConditionVariable::lck.

◆ ~ConditionVariable()

Destroy this condition variable. If the constructor allocated a new Lock for this condition variable then this Lock is also destroyed.

Definition at line 99 of file paraPthCondVar.h.

References ConditionVariable::lck.

Member Function Documentation

◆ broadcast()

void broadcast ( )

Signal on this condition variable. Broadcasting on a condition variable will wake up ALL threads that are currently waiting on the variable.

Definition at line 176 of file paraPthCondVar.h.

◆ getLock()

Lock* getLock ( ) const

Get the lock associated with this condition variable.

Returns
lock

Definition at line 188 of file paraPthCondVar.h.

References ConditionVariable::lck.

◆ lock() [1/2]

void lock ( )

Acquire the lock associated with this condition variable.

Definition at line 122 of file paraPthCondVar.h.

References Lock::lock().

◆ lock() [2/2]

void lock ( char const *  file,
int  line 
)

Acquire the lock associated with this condition variable.

Parameters
filefile name
lineline number

Definition at line 131 of file paraPthCondVar.h.

References Lock::lock().

◆ operator=()

ConditionVariable& operator= ( ConditionVariable const &  )
private

◆ setLock()

void setLock ( Lock l)

set Lock from outside.

Parameters
llock

Definition at line 110 of file paraPthCondVar.h.

References ConditionVariable::lck.

Referenced by ParaCommPth::init().

◆ signal()

void signal ( )

Signal this condition variable. Signalling a condition variable will wake up ONE thread that is currently waiting on the variable.

Definition at line 163 of file paraPthCondVar.h.

◆ unlock()

void unlock ( )

Release the lock associated with this condition variable.

Definition at line 142 of file paraPthCondVar.h.

References Lock::unlock().

◆ wait()

void wait ( )

Wait for this condition variable. The calling thread MUST hold the lock associated with this condition variable when calling this function.

Definition at line 149 of file paraPthCondVar.h.

References Lock::mtx.

Member Data Documentation

◆ cond

pthread_cond_t cond
private

The low-level condition variable.

Definition at line 62 of file paraPthCondVar.h.

◆ lck

Lock* lck
private

◆ ownMutex

bool ownMutex
private

This is true iff the constructor did allocate lck.

Definition at line 61 of file paraPthCondVar.h.