carb::tasking::ConditionVariableWrapper

Defined in carb/tasking/TaskingUtils.h

class ConditionVariableWrapper

Wrapper for carb::tasking::ConditionVariable.

Public Functions

inline ConditionVariableWrapper()

Constructs a new ConditionVariableWrapper object.

inline ConditionVariableWrapper(ITasking*)

Constructs a new ConditionVariableWrapper object.

Note

Deprecated: ITasking no longer needed.

inline ~ConditionVariableWrapper()

Destructor.

Note

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

inline void wait(Mutex *m)

Waits until the condition variable is notified.

Note

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

Parameters

m – The mutex to unlock while waiting for the condition variable to be notified.

template<class Pred>
inline void wait(Mutex *m, Pred &&pred)

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

Note

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

Parameters
  • m – The mutex 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, m is unlocked and the thread/task waits until the condition variable is notified.

template<class Rep, class Period>
inline std::cv_status wait_for(Mutex *m, const std::chrono::duration<Rep, Period> &duration)

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

Note

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

Parameters
  • m – The mutex 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 Rep, class Period, class Pred>
inline bool wait_for(Mutex *m, 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

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

Parameters
  • m – The mutex 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, 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.

template<class Clock, class Duration>
inline std::cv_status wait_until(Mutex *m, 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

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

Parameters
  • m – The mutex 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 Clock, class Duration, class Pred>
inline bool wait_until(Mutex *m, 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

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

Parameters
  • m – The mutex 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*.

inline ITasking *getTasking() const

Returns the acquired ITasking interface that was used to construct this object.

Note

Deprecated: Use carb::getCachedInterface instead.