blocxx
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>

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

◆ Condition() [1/2]

BLOCXX_NAMESPACE::Condition::Condition ( )

Construct a new Condition object.

Exceptions
Exceptionif needed system resources exhausted.

◆ ~Condition()

BLOCXX_NAMESPACE::Condition::~Condition ( )

Destroy this Condition object.

◆ Condition() [2/2]

BLOCXX_NAMESPACE::Condition::Condition ( const Condition & )
private

Member Function Documentation

◆ doTimedWait()

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

Referenced by timedWait().

◆ doWait()

void BLOCXX_NAMESPACE::Condition::doWait ( NonRecursiveMutex & mutex)
private

Referenced by wait().

◆ notifyAll()

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().

◆ notifyOne()

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

◆ operator=()

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

◆ timedWait() [1/2]

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 317 of file Condition.cpp.

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

Referenced by BLOCXX_NAMESPACE::Thread::definitiveCancel(), BLOCXX_NAMESPACE::ThreadCounter::incThreadCount(), BLOCXX_NAMESPACE::ThreadImpl::sleep(), timedWait(), BLOCXX_NAMESPACE::Semaphore::timedWait(), BLOCXX_NAMESPACE::Thread::timedWait(), and BLOCXX_NAMESPACE::ThreadCounter::waitForAll().

◆ timedWait() [2/2]

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 310 of file Condition.cpp.

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

◆ wait()

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 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(), and BLOCXX_NAMESPACE::ThreadBarrierImpl::wait().

Member Data Documentation

◆ m_condition

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: