ConditionVariableAnyWrapper#

Fully qualified name: carb::tasking::ConditionVariableAnyWrapper

Defined in carb/tasking/TaskingUtils.h

class ConditionVariableAnyWrapper#

Wrapper for carb::tasking::ConditionVariable that allows using any BasicLockable.

Warning

Although there is no strict requirement that the BasicLockable in use is tasking-aware, this is highly recommended.

Public Functions

inline ConditionVariableAnyWrapper()#

Constructs a new ConditionVariableWrapper object.

inline ~ConditionVariableAnyWrapper()#

Destructor.

Note

It is an error to destroy a condition variable that has waiting threads.

template<class Lock>
inline void wait(Lock &lock)#

Waits until the condition variable is notified.

Note

lock must be locked when calling this function. lock will be unlocked while waiting and re-locked before returning to the caller.

Template Parameters:

Lock – A BasicLockable type.

Parameters:

lock – The BasicLockable to unlock while waiting for the condition variable to be notified.

template<class Lock, class Pred>
inline void wait(
Lock &lock,
Pred &&pred,
)#

Waits until a predicate has been satisfied and the condition variable is notified.

Note

lock must be locked when calling this function. lock will be locked when calling pred and when this function returns, but unlocked while waiting.

Template Parameters:

Lock – A BasicLockable type.

Parameters:
  • lock – The BasicLockable to unlock while waiting for the condition variable to be notified.

  • pred – A predicate that is called repeatedly. When it returns true, the function returns. If it returns false, lock is unlocked and the thread/task waits until the condition variable is notified.

template<class Lock, class Rep, class Period>
inline std::cv_status wait_for(
Lock &lock,
const std::chrono::duration<Rep, Period> &duration,
)#

Waits until the condition variable is notified or the specified duration expires.

Note

lock must be locked when calling this function. lock will be unlocked while waiting and re-locked before returning to the caller.

Template Parameters:

Lock – A BasicLockable type.

Parameters:
  • lock – The BasicLockable to unlock while waiting for the condition variable to be notified.

  • duration – The amount of time to wait for.

Returns:

std::cv_status::no_timeout if the condition variable was notified; std::cv_status::timeout if the timeout period expired.

template<class Lock, class Rep, class Period, class Pred>
inline bool wait_for(
Lock &lock,
const std::chrono::duration<Rep, Period> &duration,
Pred &&pred,
)#

Waits until a predicate is satisfied and the condition variable is notified, or the specified duration expires.

Note

lock must be locked when calling this function. lock will be unlocked while waiting and re-locked before returning to the caller.

Template Parameters:

Lock – A BasicLockable type.

Parameters:
  • lock – The BasicLockable to unlock while waiting for the condition variable to be notified.

  • duration – The amount of time to wait for.

  • pred – A predicate that is called repeatedly. When it returns true, the function returns. If it returns false, lock is unlocked and the thread/task waits until the condition variable is notified.

Returns:

true if the predicate was satisfied; false if a timeout occurred.

template<class Lock, class Clock, class Duration>
inline std::cv_status wait_until(
Lock &lock,
const std::chrono::time_point<Clock, Duration> &time_point,
)#

Waits until the condition variable is notified or the clock reaches the given time point.

Note

lock must be locked when calling this function. lock will be unlocked while waiting and re-locked before returning to the caller.

Template Parameters:

Lock – A BasicLockable type.

Parameters:
  • lock – The BasicLockable to unlock while waiting for the condition variable to be notified.

  • time_point – The clock time to wait until.

Returns:

std::cv_status::no_timeout if the condition variable was notified; std::cv_status::timeout if the timeout period expired.

template<class Lock, class Clock, class Duration, class Pred>
inline bool wait_until(
Lock &lock,
const std::chrono::time_point<Clock, Duration> &time_point,
Pred &&pred,
)#

Waits until a predicate is satisfied and the condition variable is notified or the clock reaches the given time point.

Note

lock must be locked when calling this function. lock will be unlocked while waiting and re-locked before returning to the caller.

Template Parameters:

Lock – A BasicLockable type.

Parameters:
  • lock – The BasicLockable to unlock while waiting for the condition variable to be notified.

  • time_point – The clock time to wait until.

  • pred – A predicate that is called repeatedly. When it returns true, the function returns. If it returns false, m is unlocked and the thread/task waits until the condition variable is notified.

Returns:

true if the predicate was satisfied; false if a timeout occurred.

inline void notify_one()#

Notifies one waiting thread/task to wake and check the predicate (if applicable).

inline void notify_all()#

Notifies all waiting threads/tasks to wake and check the predicate (if applicable).

inline operator ConditionVariable*() const#

Convertible to ConditionVariable*.