blocxx
Public Member Functions | Private Member Functions | Private Attributes

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) BLOCXX_DEPRECATED
 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:
Exceptionif needed system resources exhausted.
BLOCXX_NAMESPACE::Condition::~Condition ( )

Destroy this Condition object.

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

Member Function Documentation

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

Signal all threads that are currently waiting on the Condition object.

This will cause all threads waiting on a call to 'wait' or timedWait to stop blocking and continue execution.

Exceptions:
noexceptions

Referenced by BLOCXX_NAMESPACE::Thread::cancel_internal(), BLOCXX_NAMESPACE::ThreadCounter::decThreadCount(), BLOCXX_NAMESPACE::Thread::doneRunning(), BLOCXX_NAMESPACE::ThreadCounter::setMax(), BLOCXX_NAMESPACE::Semaphore::signal(), and BLOCXX_NAMESPACE::ThreadBarrierImpl::wait().

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:
noexceptions
Condition& BLOCXX_NAMESPACE::Condition::operator= ( const Condition ) [private]
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:
lockThe mutex lock object that must be acquired before calling this method.
timeoutThe 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 321 of file Condition.cpp.

Referenced by BLOCXX_NAMESPACE::Thread::definitiveCancel(), BLOCXX_NAMESPACE::ThreadCounter::incThreadCount(), BLOCXX_NAMESPACE::ThreadImpl::sleep(), BLOCXX_NAMESPACE::Thread::timedWait(), BLOCXX_NAMESPACE::Semaphore::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:
lockThe mutex lock object that must be acquired before calling this method.
sTimeoutThe number of seconds to wait for this Condition to get signalled.
usTimeoutThe 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 314 of file Condition.cpp.

References BLOCXX_NAMESPACE::NonRecursiveMutexLock::isLocked().

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:
lockThe mutex lock object that must be acquired before calling this method.
Exceptions:
ThreadCancelledException

Definition at line 304 of file Condition.cpp.

Referenced by BLOCXX_NAMESPACE::ThreadBarrierImpl::wait(), and BLOCXX_NAMESPACE::Semaphore::wait().


Member Data Documentation

ConditionVar_t BLOCXX_NAMESPACE::Condition::m_condition [private]

Definition at line 150 of file Condition.hpp.


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