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

Wakes a thread that waits with any lock it can drop and retake. More...

#include <StormByte/safe/condition_variable_any.hxx>

Public Member Functions

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

Detailed Description

Wakes a thread that waits with any lock it can drop and retake.

Not a ConditionVariable. That one accepts only UniqueLock. This one accepts UniqueLock, SharedLock and any other lock with lock() and unlock(). The signal lives on Base's heap. A spurious wake is valid. The predicate overloads filter it in the caller.

Constructor & Destructor Documentation

◆ ConditionVariableAny() [1/3]

StormByte::Safe::ConditionVariableAny::ConditionVariableAny ( )

Condition with no waiters.

Exceptions
AllocationErrorThe signal cannot be allocated.

◆ ConditionVariableAny() [2/3]

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

◆ ConditionVariableAny() [3/3]

StormByte::Safe::ConditionVariableAny::ConditionVariableAny ( ConditionVariableAny && )
delete

◆ ~ConditionVariableAny()

StormByte::Safe::ConditionVariableAny::~ConditionVariableAny ( )
noexcept

Destroys the signal on Base's heap.

Note
No thread may be waiting.

Member Function Documentation

◆ notify_all()

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

Wake every waiter.

◆ notify_one()

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

Wake one waiter.

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ wait() [1/2]

template<class Lock>
requires requires(Lock& lock) { lock.lock(); lock.unlock(); }
void StormByte::Safe::ConditionVariableAny::wait ( Lock & lock)
inline

Wait until notified.

May wake spuriously.

Template Parameters
LockLock with lock() and unlock().
Parameters
lockLock held by the caller. Dropped while waiting and retaken before return.
Precondition
lock owns its mutex.
Exceptions
OperationErrorA foreign failure is translated.

◆ wait() [2/2]

template<class Lock, class Predicate>
requires requires(Lock& lock) { lock.lock(); lock.unlock(); }
void StormByte::Safe::ConditionVariableAny::wait ( Lock & lock,
Predicate pred )
inline

Wait until pred is true.

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

◆ wait_for() [1/2]

template<class Lock, class Rep, class Period>
requires requires(Lock& lock) { lock.lock(); lock.unlock(); }
CvStatus StormByte::Safe::ConditionVariableAny::wait_for ( Lock & lock,
const std::chrono::duration< Rep, Period > & rel )
inline

Wait until notified or rel elapses.

Template Parameters
LockLock with lock() and unlock().
RepTick representation of rel.
PeriodTick period of rel.
Parameters
lockLock held by the caller.
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 Lock, class Rep, class Period, class Predicate>
requires requires(Lock& lock) { lock.lock(); lock.unlock(); }
bool StormByte::Safe::ConditionVariableAny::wait_for ( Lock & lock,
const std::chrono::duration< Rep, Period > & rel,
Predicate pred )
inline

Wait until pred is true or rel elapses.

Template Parameters
LockLock with lock() and unlock().
RepTick representation of rel.
PeriodTick period of rel.
PredicateCallable invoked with the lock held. Its result is tested as a bool.
Parameters
lockLock held by the caller.
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 Lock, class Clock, class Duration>
requires requires(Lock& lock) { lock.lock(); lock.unlock(); }
CvStatus StormByte::Safe::ConditionVariableAny::wait_until ( Lock & lock,
const std::chrono::time_point< Clock, Duration > & abs )
inline

Wait until notified or abs is reached.

Template Parameters
LockLock with lock() and unlock().
ClockClock of abs.
DurationDuration of abs.
Parameters
lockLock held by the caller.
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 Lock, class Clock, class Duration, class Predicate>
requires requires(Lock& lock) { lock.lock(); lock.unlock(); }
bool StormByte::Safe::ConditionVariableAny::wait_until ( Lock & lock,
const std::chrono::time_point< Clock, Duration > & abs,
Predicate pred )
inline

Wait until pred is true or abs is reached.

Template Parameters
LockLock with lock() and unlock().
ClockClock of abs.
DurationDuration of abs.
PredicateCallable invoked with the lock held. Its result is tested as a bool.
Parameters
lockLock held by the caller.
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: