|
ion 0.12.0
Atomic concurrency support library
|
Reusable thread-coordination mechanism similar to ion::Barrier but allows control where the completion function is invoked. More...
#include <ion/barrier.hpp>
Public Member Functions | |
| constexpr | FlexBarrier (std::uint32_t expected, CompletionFunction func=CompletionFunction()) noexcept |
| Construct new barrier with an expected count of expected. | |
| template<class WaitFunction = detail::NoOp> | |
| void | ArriveAndWait (InvokePolicy policy, std::uint32_t n=1u, WaitFunction &&wait=WaitFunction()) noexcept |
| Arrives at barrier, waits until number of arrivals reaches the expected number and depending on policy it may execute the completion function. | |
FlexBarrier requires stable address and is neither copyable or movable. | |
| FlexBarrier (FlexBarrier const &)=delete | |
| FlexBarrier & | operator= (FlexBarrier const &)=delete |
Static Public Member Functions | |
| static constexpr auto | Max () noexcept -> std::uint32_t |
Reusable thread-coordination mechanism similar to ion::Barrier but allows control where the completion function is invoked.
| CompletionFunction | no-except invocable function, invoked by one of the threads that arrive at the barrier via ArriveAndWait() and specified policy InvokePolicy::Allowed. |
All calls to ArriveAndWait() synchronizes-with any calls to ArriveAndWait().
The CompletionFunction synchronizes-with calls to ArriveAndWait() after it is executed. This means that no additional synchronization is necessary in the CompletionFunction* w.r.t. to the threads that have arrived and is waiting for departure.
|
explicitconstexprnoexcept |
Construct new barrier with an expected count of expected.
| expected | Expected number of arrivals. |
| func | Completion function invoked at most once for every barrier phase. phases arrival and departure. |
|
noexcept |
Arrives at barrier, waits until number of arrivals reaches the expected number and depending on policy it may execute the completion function.
Decrements the expected count by n and iff policy == InvokePolicy::Allowed then it may also invoke the completion function.
This function executes atomically. The call to this function strongly happens-before the start of the phase completion step for the current phase.
The behavior is undefined if n is less than or equal to 0 or greater than the expected count for the current barrier phase.
| policy | Policy indicating whether the completion function is allowed to be invoked. |
| n | the value by which the expected count will be decreased. |
| wait | function invoked repeatedly while waiting for barrier to be lifted. The wait function is invoked without any synchronization guaranteees and may or may not be invoked at all if calling thread does not have to wait. If it is desired that all threads leave barrier at the same time, user should take special care to not introduce any latency in WaitFunction such that the thread may lag. Generally this feature should be avoided if possible. |
| WaitFunction | no-except invocable function with signature void() noexcept. Default type is a no-op. See wait argument for details. |
|
staticconstexprnoexcept |