StormByte 3.0.0
C++26 foundation of the StormByte suite
Loading...
Searching...
No Matches
StormByte::Safe::ConditionVariable Class Reference

Wakes threads waiting on a Mutex. More...

#include <StormByte/safe/condition_variable.hxx>

Public Member Functions

 ConditionVariable ()
 Condition with no waiters.
 ConditionVariable (const ConditionVariable &)=delete
 ConditionVariable (ConditionVariable &&)=delete
 ~ConditionVariable () noexcept
 Destroys the signal on Base's heap.
ConditionVariable & operator= (const ConditionVariable &)=delete
ConditionVariable & operator= (ConditionVariable &&)=delete
void notify_one () noexcept
 Wake one waiter.
void notify_all () noexcept
 Wake every waiter.
void wait (UniqueLock &lock)
 Wait until notified.
template<class Predicate>
void wait (UniqueLock &lock, Predicate pred)
 Wait until pred is true.
template<class Rep, class Period>
CvStatus wait_for (UniqueLock &lock, const std::chrono::duration< Rep, Period > &rel)
 Wait until notified or rel elapses.
template<class Rep, class Period, class Predicate>
bool wait_for (UniqueLock &lock, const std::chrono::duration< Rep, Period > &rel, Predicate pred)
 Wait until pred is true or rel elapses.
template<class Clock, class Duration>
CvStatus wait_until (UniqueLock &lock, const std::chrono::time_point< Clock, Duration > &abs)
 Wait until notified or abs is reached.
template<class Clock, class Duration, class Predicate>
bool wait_until (UniqueLock &lock, const std::chrono::time_point< Clock, Duration > &abs, Predicate pred)
 Wait until pred is true or abs is reached.

Detailed Description

Wakes threads waiting on a Mutex.

Accepts only UniqueLock. The signal lives on Base's heap. A spurious wake is valid. The predicate overloads filter it in the caller.

Constructor & Destructor Documentation

◆ ConditionVariable() [1/3]

StormByte::Safe::ConditionVariable::ConditionVariable ( )

Condition with no waiters.

Exceptions
AllocationErrorThe signal cannot be allocated.

◆ ConditionVariable() [2/3]

StormByte::Safe::ConditionVariable::ConditionVariable ( const ConditionVariable & )
delete

◆ ConditionVariable() [3/3]

StormByte::Safe::ConditionVariable::ConditionVariable ( ConditionVariable && )
delete

◆ ~ConditionVariable()

StormByte::Safe::ConditionVariable::~ConditionVariable ( )
noexcept

Destroys the signal on Base's heap.

Note
No thread may be waiting.

Member Function Documentation

◆ notify_all()

void StormByte::Safe::ConditionVariable::notify_all ( )
noexcept

Wake every waiter.

◆ notify_one()

void StormByte::Safe::ConditionVariable::notify_one ( )
noexcept

Wake one waiter.

◆ operator=() [1/2]

ConditionVariable & StormByte::Safe::ConditionVariable::operator= ( ConditionVariable && )
delete

◆ operator=() [2/2]

ConditionVariable & StormByte::Safe::ConditionVariable::operator= ( const ConditionVariable & )
delete

◆ wait() [1/2]

void StormByte::Safe::ConditionVariable::wait ( UniqueLock & lock)

Wait until notified.

May wake spuriously.

Parameters
lockLock that owns the mutex. Dropped while waiting and retaken before return.
Precondition
lock owns its mutex.
Exceptions
OperationErrorA foreign failure is translated.

◆ wait() [2/2]

template<class Predicate>
void StormByte::Safe::ConditionVariable::wait ( UniqueLock & lock,
Predicate pred )
inline

Wait until pred is true.

Template Parameters
PredicateCallable invoked with the lock held. Its result is tested as a bool.
Parameters
lockLock that owns the mutex.
predPredicate. Evaluated in the caller.
Precondition
lock owns its mutex.
Exceptions
OperationErrorThe unpredicated wait translated a foreign failure.

◆ wait_for() [1/2]

template<class Rep, class Period>
CvStatus StormByte::Safe::ConditionVariable::wait_for ( UniqueLock & lock,
const std::chrono::duration< Rep, Period > & rel )
inline

Wait until notified or rel elapses.

Template Parameters
RepTick representation of rel.
PeriodTick period of rel.
Parameters
lockLock that owns the mutex.
relRelative timeout.
Returns
Whether the wait timed out. A spurious wake is CvStatus::NoTimeout.
Precondition
lock owns its mutex.
Exceptions
OperationErrorA foreign failure is translated.

◆ wait_for() [2/2]

template<class Rep, class Period, class Predicate>
bool StormByte::Safe::ConditionVariable::wait_for ( UniqueLock & lock,
const std::chrono::duration< Rep, Period > & rel,
Predicate pred )
inline

Wait until pred is true or rel elapses.

Template Parameters
RepTick representation of rel.
PeriodTick period of rel.
PredicateCallable invoked with the lock held. Its result is tested as a bool.
Parameters
lockLock that owns the mutex.
relRelative timeout.
predPredicate. Evaluated in the caller.
Returns
Whether pred is true on return.
Precondition
lock owns its mutex.
Exceptions
OperationErrorA foreign failure is translated.

◆ wait_until() [1/2]

template<class Clock, class Duration>
CvStatus StormByte::Safe::ConditionVariable::wait_until ( UniqueLock & lock,
const std::chrono::time_point< Clock, Duration > & abs )
inline

Wait until notified or abs is reached.

Template Parameters
ClockClock of abs.
DurationDuration of abs.
Parameters
lockLock that owns the mutex.
absAbsolute time.
Returns
Whether the wait timed out.
Precondition
lock owns its mutex.
Exceptions
OperationErrorA foreign failure is translated.

◆ wait_until() [2/2]

template<class Clock, class Duration, class Predicate>
bool StormByte::Safe::ConditionVariable::wait_until ( UniqueLock & lock,
const std::chrono::time_point< Clock, Duration > & abs,
Predicate pred )
inline

Wait until pred is true or abs is reached.

Template Parameters
ClockClock of abs.
DurationDuration of abs.
PredicateCallable invoked with the lock held. Its result is tested as a bool.
Parameters
lockLock that owns the mutex.
absAbsolute time.
predPredicate. Evaluated in the caller.
Returns
Whether pred is true on return.
Precondition
lock owns its mutex.
Exceptions
OperationErrorA foreign failure is translated.

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