BLOCXX_NAMESPACE::Condition Class Reference

The Condition class represents a synchronization device that allows threads to suspend execution and relinquish the processors until another thread signals the condition. More...

#include <Condition.hpp>

List of all members.

Public Member Functions

 Condition ()
 Construct a new Condition object.
 ~Condition ()
 Destroy this Condition object.
void notifyOne ()
 Signal one thread that is currently waiting on the Condition object through the wait or timedWait methods.
void notifyAll ()
 Signal all threads that are currently waiting on the Condition object.
void wait (NonRecursiveMutexLock &lock)
 Atomically unlock a given mutex and wait for the this Condition object to get signalled.
bool timedWait (NonRecursiveMutexLock &lock, const Timeout &timeout)
 Atomically unlock a given mutex and wait for a given amount of time for this Condition object to get signalled.
bool timedWait (NonRecursiveMutexLock &lock, UInt32 sTimeout, UInt32 usTimeout=0)
 Atomically unlock a given mutex and wait for a given amount of time for this Condition object to get signalled.

Private Member Functions

 Condition (const Condition &)
Conditionoperator= (const Condition &)
void doWait (NonRecursiveMutex &mutex)
bool doTimedWait (NonRecursiveMutex &mutex, const Timeout &timeout)

Private Attributes

ConditionVar_t m_condition


Detailed Description

The Condition class represents a synchronization device that allows threads to suspend execution and relinquish the processors until another thread signals the condition.

The thread that signals the Condition object has the option of only letting one waiting thread receive the notification, or all threads.

Note that descriptions of what exceptions may be thrown assumes that object is used correctly, i.e. method preconditions are satisfied.

Definition at line 62 of file Condition.hpp.


Constructor & Destructor Documentation

BLOCXX_NAMESPACE::Condition::Condition (  ) 

Construct a new Condition object.

Exceptions:
Exception if needed system resources exhausted.

Definition at line 59 of file Condition.cpp.

References BLOCXX_THROW, and PTHREAD_COND_ATTR_DEFAULT.

BLOCXX_NAMESPACE::Condition::~Condition (  ) 

Destroy this Condition object.

Definition at line 68 of file Condition.cpp.

References m_condition.

BLOCXX_NAMESPACE::Condition::Condition ( const Condition  )  [private]


Member Function Documentation

void BLOCXX_NAMESPACE::Condition::notifyOne (  ) 

Signal one thread that is currently waiting on the Condition object through the wait or timedWait methods.

All other threads waiting on this object through wait or timedWait will continue to block.

Exceptions:
no exceptions

Definition at line 75 of file Condition.cpp.

References m_condition.

Referenced by BLOCXX_NAMESPACE::GenericRWLockImpl< IdT, CompareT >::releaseWriteLock().

void BLOCXX_NAMESPACE::Condition::notifyAll (  ) 

void BLOCXX_NAMESPACE::Condition::wait ( NonRecursiveMutexLock lock  ) 

Atomically unlock a given mutex and wait for the this Condition object to get signalled.

The thread execution is suspended and does not consume any CPU time until the Condition object is notified (signalled). The mutex lock must be locked by the calling thread on entrance to wait. Before returning to the calling thread, wait re-acquires the mutex lock. This function should always be called within a while loop that checks the condition.

Parameters:
lock The mutex lock object that must be acquired before calling this method.
Exceptions:
ThreadCancelledException 

Definition at line 300 of file Condition.cpp.

References BLOCXX_THROW, doWait(), BLOCXX_NAMESPACE::NonRecursiveMutexLock::isLocked(), and BLOCXX_NAMESPACE::NonRecursiveMutexLock::m_mutex.

Referenced by BLOCXX_NAMESPACE::Semaphore::wait().

bool BLOCXX_NAMESPACE::Condition::timedWait ( NonRecursiveMutexLock lock,
const Timeout timeout 
)

Atomically unlock a given mutex and wait for a given amount of time for this Condition object to get signalled.

The thread execution is suspended and does not consume any CPU time until the Condition object is notified (signalled). The mutex lock must be locked by the calling thread on entrance to wait. Before returning to the calling thread, wait re-acquires the mutex lock. This function should always be called within a while loop that checks the condition.

Parameters:
lock The mutex lock object that must be acquired before calling this method.
timeout The time to wait for the condition to be signalled. Because of spurious wakeups, it is recommended that an absolute time timeout is used.
Returns:
true if condition was signaled within the duration, false if timeout occurred.
Exceptions:
ThreadCancelledException 

Definition at line 317 of file Condition.cpp.

References BLOCXX_THROW, doTimedWait(), BLOCXX_NAMESPACE::NonRecursiveMutexLock::isLocked(), and BLOCXX_NAMESPACE::NonRecursiveMutexLock::m_mutex.

Referenced by BLOCXX_NAMESPACE::GenericRWLockImpl< IdT, CompareT >::acquireReadLock(), BLOCXX_NAMESPACE::GenericRWLockImpl< IdT, CompareT >::acquireWriteLock(), BLOCXX_NAMESPACE::Thread::definitiveCancel(), BLOCXX_NAMESPACE::ThreadCounter::incThreadCount(), BLOCXX_NAMESPACE::ThreadImpl::sleep(), BLOCXX_NAMESPACE::Thread::timedWait(), BLOCXX_NAMESPACE::Semaphore::timedWait(), timedWait(), and BLOCXX_NAMESPACE::ThreadCounter::waitForAll().

bool BLOCXX_NAMESPACE::Condition::timedWait ( NonRecursiveMutexLock lock,
UInt32  sTimeout,
UInt32  usTimeout = 0 
)

Atomically unlock a given mutex and wait for a given amount of time for this Condition object to get signalled.

The thread execution is suspended and does not consume any CPU time until the Condition object is notified (signalled). The mutex lock must be locked by the calling thread on entrance to wait. Before returning to the calling thread, wait re-acquires the mutex lock. This function should always be called within a while loop that checks the condition.

Parameters:
lock The mutex lock object that must be acquired before calling this method.
sTimeout The number of seconds to wait for this Condition to get signalled.
usTimeout The number of micro seconds (1/1000000th) to wait for this Condition to get signalled. The total wait time is sTimeout * 1000000 + usTimeout micro seconds. This function should always be called within a while loop that checks the condition.
Returns:
true if the lock was acquired, false if timeout occurred.
Exceptions:
ThreadCancelledException 

Definition at line 310 of file Condition.cpp.

References BLOCXX_NAMESPACE::Timeout::relative(), and timedWait().

Condition& BLOCXX_NAMESPACE::Condition::operator= ( const Condition  )  [private]

void BLOCXX_NAMESPACE::Condition::doWait ( NonRecursiveMutex mutex  )  [private]

bool BLOCXX_NAMESPACE::Condition::doTimedWait ( NonRecursiveMutex mutex,
const Timeout timeout 
) [private]


Member Data Documentation

Definition at line 150 of file Condition.hpp.

Referenced by doTimedWait(), doWait(), notifyAll(), notifyOne(), and ~Condition().


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

Generated on Wed Feb 25 19:05:02 2009 for blocxx by  doxygen 1.5.6