CoopSync for TBB 0.1.0
Cooperative synchronization primitives for TBB resumable tasks
Loading...
Searching...
No Matches
coopsync_tbb::barrier< CompletionFunction > Class Template Reference

A barrier is a reusable synchronization primitive that allows tasks to suspend until a certain number of arrivals have occurred. The barrier is reusable, meaning that once the expected number of arrivals has been reached and the completion function has been called, the barrier can be used again for the next phase. Concurrent invocations of the member functions. except for destructor, are safe. More...

#include <coopsync_tbb/barrier.hpp>

Classes

class  arrival_token
 An opaque value representing task arrival at the barrier. It is used to wait for the completion of a phase. More...

Public Member Functions

 barrier (std::ptrdiff_t expected, CompletionFunction completion=detail::barrier::completion)
 Constructs a barrier with the specified initial expected count and completion function.
 barrier (const barrier &)=delete
 Barrier is not copy-constructible.
barrier & operator= (const barrier &)=delete
 Barrier is not copy-assignable.
 barrier (barrier &&)=delete
 Barrier is not move-constructible.
barrier & operator= (barrier &&)=delete
 Barrier is not move-assignable.
 ~barrier ()
 Destroys the mutex.
arrival_token arrive (std::ptrdiff_t update=1)
 Arrives at the barrier with the specified update. Constructs an arrival token associated with the current phase and decrement the expected count by the update. If the expected count reaches zero, the completion function is called and all waiting tasks are resumed.
void wait (arrival_token arrival)
 Waits for the completion of the phase associated with the given arrival token. If the token is associated with the current phase, the task is suspended until the phase is complete. If the token is associate with the immediately previous phase, the function returns immediately. Token associated with any other phase must not be used.
void arrive_and_wait ()
 Decrements the expected counter by 1 and waits for the completion of the current phase. If the expected counter for the current phase reaches zero, the completion function is called and all waiting tasks are resumed. Equivalent to wait(arrive()).
void arrive_and_drop ()
 Decrements the initial expected count for the following phases by 1 and decrements the expect count for the current phase by 1. If the expected count for the current phase reaches zero, the completion function is called and all waiting tasks are resumed.

Static Public Member Functions

static constexpr std::ptrdiff_t max () noexcept
 Returns the maximum value for the barrier counter.

Detailed Description

template<typename CompletionFunction = detail::barrier::default_completion_t>
class coopsync_tbb::barrier< CompletionFunction >

A barrier is a reusable synchronization primitive that allows tasks to suspend until a certain number of arrivals have occurred. The barrier is reusable, meaning that once the expected number of arrivals has been reached and the completion function has been called, the barrier can be used again for the next phase. Concurrent invocations of the member functions. except for destructor, are safe.

Template Parameters
CompletionFunctionThe type of the completion function to be called when a phase completes. The completion function must be not throw and must be invocable without arguments.

Constructor & Destructor Documentation

◆ barrier()

template<typename CompletionFunction>
coopsync_tbb::barrier< CompletionFunction >::barrier ( std::ptrdiff_t expected,
CompletionFunction completion = detail::barrier< CompletionFunction >::completion )
inlineexplicit

Constructs a barrier with the specified initial expected count and completion function.

Parameters
expectedThe initial expected count for the barrier. Must be non-negative and not greater than max().
completionThe completion function to be called when a phase completes. The default completion function does nothing. The completion function must be not throw.

◆ ~barrier()

template<typename CompletionFunction>
coopsync_tbb::barrier< CompletionFunction >::~barrier ( )
inline

Destroys the mutex.

Note
The destructor must not be called while there are still tasks waiting on the barrier. The destructor doesn not notify or resume any waiting tasks.

Member Function Documentation

◆ arrive()

template<typename CompletionFunction>
barrier< CompletionFunction >::arrival_token coopsync_tbb::barrier< CompletionFunction >::arrive ( std::ptrdiff_t update = 1)
inlinenodiscard

Arrives at the barrier with the specified update. Constructs an arrival token associated with the current phase and decrement the expected count by the update. If the expected count reaches zero, the completion function is called and all waiting tasks are resumed.

Parameters
updateThe value to decrement the expected count by. Must be non-negative and less than or equal to the current expected count.
Returns
An arrival token associated with the current phase.

◆ max()

template<typename CompletionFunction>
std::ptrdiff_t coopsync_tbb::barrier< CompletionFunction >::max ( )
inlinestaticconstexprnoexcept

Returns the maximum value for the barrier counter.

Returns
The maximum value for the barrier counter.

◆ wait()

template<typename CompletionFunction>
void coopsync_tbb::barrier< CompletionFunction >::wait ( arrival_token arrival)
inline

Waits for the completion of the phase associated with the given arrival token. If the token is associated with the current phase, the task is suspended until the phase is complete. If the token is associate with the immediately previous phase, the function returns immediately. Token associated with any other phase must not be used.

Parameters
arrivalThe arrival token associated with the current phase or the immediately previous phase.

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