ONPOSIX  2.0
 All Classes Namespaces Files Functions Variables Enumerator Friends Macros Pages
PosixCondition Class Reference

Implementation of a condition variable. More...

#include <PosixCondition.hpp>

Public Member Functions

 PosixCondition ()
 Constructor. Initialize the condition variable.
 ~PosixCondition ()
 Destructor. Destroys the condition variable.
int wait (PosixMutex *m)
 Blocks the calling thread on the condition variable.
int timedWait (PosixMutex *m, const Time &abstime)
 Blocks the calling thread on the condition variable.
int signal ()
 Unblocks at least one of the blocked threads.
int signalAll ()
 Unblocks all blocked threads.

Private Member Functions

 PosixCondition (const PosixMutex &)
PosixConditionoperator= (const PosixMutex &)

Private Attributes

pthread_cond_t cond_

Detailed Description

Implementation of a condition variable.

The class is non copyable and makes use of the pthread library.

Definition at line 38 of file PosixCondition.hpp.

Constructor & Destructor Documentation

PosixCondition ( const PosixMutex )
private

Constructor. Initialize the condition variable.

Exceptions
runtime_errorif the initialization of the condition variable fails.

Definition at line 35 of file PosixCondition.cpp.

{
if (pthread_cond_init(&cond_, NULL) != 0)
throw std::runtime_error(std::string("Error: ") + strerror(errno));
}

Destructor. Destroys the condition variable.

Definition at line 44 of file PosixCondition.cpp.

{
VERIFY_ASSERTION(!pthread_cond_destroy(&cond_));
}

Member Function Documentation

PosixCondition& operator= ( const PosixMutex )
private
int signal ( )
inline

Unblocks at least one of the blocked threads.

Returns
0 in case of success

Definition at line 82 of file PosixCondition.hpp.

{
return pthread_cond_signal(&cond_);
}

Here is the caller graph for this function:

int signalAll ( )
inline

Unblocks all blocked threads.

Returns
0 in case of success

Definition at line 91 of file PosixCondition.hpp.

{
return pthread_cond_broadcast(&cond_);
}
int timedWait ( PosixMutex m,
const Time abstime 
)
inline

Blocks the calling thread on the condition variable.

These functions atomically release mutex and cause the calling thread to block on the condition variable.

Parameters
mMutex released when blocking and acquired when unblocking.
abstimeAbsolute time for timeout
Returns
0 in case of success, ETIMEDOUT in case of timeout

Definition at line 70 of file PosixCondition.hpp.

{
timespec ts;
ts.tv_sec = abstime.getSeconds();
ts.tv_nsec = abstime.getNSeconds();
return pthread_cond_timedwait(&cond_, &(m->mutex_), &ts);
}

Here is the call graph for this function:

int wait ( PosixMutex m)
inline

Blocks the calling thread on the condition variable.

These functions atomically release mutex and cause the calling thread to block on the condition variable.

Parameters
mMutex released when blocking and acquired when unblocking.
Returns
0 in case of success

Definition at line 57 of file PosixCondition.hpp.

{
return pthread_cond_wait(&cond_, &(m->mutex_));
}

Here is the caller graph for this function:

Member Data Documentation

pthread_cond_t cond_
private

Definition at line 43 of file PosixCondition.hpp.


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