|
ion 0.12.0
Atomic concurrency support library
|
Reusable thread-coordination mechanism modelled after std::barrier.
More...
#include <ion/barrier.hpp>
Public Member Functions | |
| constexpr | Barrier (std::ptrdiff_t expected, CompletionFunction func=CompletionFunction()) noexcept |
| Construct new barrier with an expected count of expected. | |
| auto | Arrive (std::ptrdiff_t n=1) noexcept -> ArrivalToken |
| Arrives at barrier, possibly executing completion function and returns token. | |
| void | Wait (ArrivalToken &&token) const noexcept |
| Block at the barrier synchronization point associated with token. | |
| void | ArriveAndWait (std::ptrdiff_t n=1) noexcept |
Equivalent to barrier.Wait(barrier.Arrive(n)) | |
| void | ArriveAndDrop () noexcept |
| Decrements both the initial expected count for subsequent phases and the expected count for current phase by one. | |
Barrier requires stable address and is neither copyable or movable. | |
| Barrier (Barrier const &)=delete | |
| Barrier & | operator= (Barrier const &)=delete |
Static Public Member Functions | |
| static constexpr auto | Max () noexcept -> std::ptrdiff_t |
Reusable thread-coordination mechanism modelled after std::barrier.
Modelled after C++20 std::barrier but does not perform system calls or yields and as such is more suitable in a real-time environment. Notable differences:
A Barrier phase consist of two states:
| CompletionFunction | no-except invocable function, invoked by one of the threads that arrive at the barrier via Arrive(), ArriveAndWait() or ArriveAndDrop(). |
All calls to ArriveAndWait() or ArriveAndDrop() synchronizes-with any calls to ArriveAndWait() or Wait().
The CompletionFunction synchronizes-with calls to ArriveAndWait() or Wait() 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 once for every barrier phase. phases arrival and departure. |
|
nodiscardnoexcept |
Arrives at barrier, possibly executing completion function and returns token.
Constructs an ArrivalToken object associated with the phase synchronization point for the current phase. Then, decrements the expected count by n.
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.
| n | the value by which the expected count will be decreased. |
|
noexcept |
Decrements both the initial expected count for subsequent phases and the expected count for current phase by one.
Unlike ArriveAndWait it will not wait.
|
noexcept |
Equivalent to barrier.Wait(barrier.Arrive(n))
| n | the value by which the expected count will be decreased. |
|
staticconstexprnoexcept |
|
noexcept |
Block at the barrier synchronization point associated with token.
If arrival is associated with the phase synchronization point for the current phase of *this, blocks at the synchronization point associated with arrival until the phase completion step of the synchronization point's phase is run.
Otherwise, if arrival is associated with the phase synchronization point for the immediately preceding phase of *this, returns immediately. Otherwise, i.e. if arrival is associated with the phase synchronization point for an earlier phase of *this or any phase of a barrier object other than *this, the behavior is undefined.
| token | Arrival token from previous call to Arrive(). |