carb::tasking::TaskGroup

Defined in carb/tasking/TaskingUtils.h

class TaskGroup

TaskGroup is a small and fast counter for tasks.

TaskGroup blocks when tasks have “entered” the TaskGroup. It becomes signaled when all tasks have left the TaskGroup.

Public Functions

constexpr TaskGroup() = default

Constructs an empty TaskGroup.

inline ~TaskGroup()

TaskGroup destructor.

Warning

It is an error to destroy a TaskGroup that is not empty. Doing so can result in memory corruption.

inline bool empty() const

Returns (with high probability) whether the TaskGroup is empty.

As TaskGroup atomically tracks tasks, this function may return an incorrect value as another task may have entered or left the TaskGroup before the return value could be processed.

Returns

true if there is high probability that the TaskGroup is empty (signaled); false otherwise.

inline void enter()

“Enters” the TaskGroup.

Warning

Every call to this function must be paired with leave(). It is generally better to use with().

inline void leave()

“Leaves” the TaskGroup.

Warning

Every call to this function must be paired with an earlier enter() call. It is generally better to use with().

inline bool try_wait() const

Returns true if the TaskGroup is empty (signaled) with high probability.

Returns

true if there is high probability that the TaskGroup is empty (signaled); false otherwise.

inline void wait() const

Blocks the calling thread or task until the TaskGroup becomes empty.

template<class Rep, class Period>
inline bool try_wait_for(std::chrono::duration<Rep, Period> dur)

Blocks the calling thread or task until the TaskGroup becomes empty or the given duration elapses.

Parameters

dur – The duration to wait for.

Returns

true if the TaskGroup has become empty; false if the duration elapses.

template<class Clock, class Duration>
inline bool try_wait_until(std::chrono::time_point<Clock, Duration> when)

Blocks the calling thread or task until the TaskGroup becomes empty or the given time is reached.

Parameters

when – The time to wait until.

Returns

true if the TaskGroup has become empty; false if the given time is reached.

template<class ...Args>
inline auto with(Args&&... args)

A helper function for entering the TaskGroup during a call to invoke() and leaving afterwards.

Parameters

args – Arguments to pass to carb::cpp::invoke. The TaskGroup is entered (via enter()) before the invoke and left (via leave()) when the invoke completes.

Returns

the value returned by carb::cpp::invoke.