Single use thread-coordination mechanism modelled after std::latch.
More...
#include <ion/latch.hpp>
|
| constexpr | Latch (std::ptrdiff_t expected) noexcept |
| | Construct latch with expected number of arrivals.
|
| |
| void | CountDown (std::ptrdiff_t n=1) noexcept |
| | Decrements expected count by n without waiting.
|
| |
| bool | TryWait () const noexcept |
| | Equivalent to Wait().
|
| |
|
void | Wait () const noexcept |
| | Block until expected count reaches zero.
|
| |
| void | ArriveAndWait (std::ptrdiff_t n=1) noexcept |
| | Decrements expected count by n and waits.
|
| |
|
|
| Latch (Latch const &)=delete |
| |
|
Latch & | operator= (Latch const &)=delete |
| |
|
| static constexpr std::ptrdiff_t | Max () noexcept |
| |
Single use thread-coordination mechanism modelled after std::latch.
Modelled after C++20 std::latch but does not perform system calls or yields and as such is more suitable in a real-time environment. Notable differences:
Latch has two states:
- arrival, when threads fetch and decrement the expected count
- departure, when all threads have arrived and will depart.
After departure the only allowed operation is to delete the latch.
- Memory Order
All calls to ArriveAndWait() or CountDown() synchronizes-with any calls to ArriveAndWait() or Wait().
- Thread Safety
- thread-safe
◆ Latch()
| ion::Latch::Latch |
( |
std::ptrdiff_t | expected | ) |
|
|
inlineexplicitconstexprnoexcept |
Construct latch with expected number of arrivals.
- Parameters
-
| expected | Expected number of arrivals. |
◆ ArriveAndWait()
| void ion::Latch::ArriveAndWait |
( |
std::ptrdiff_t | n = 1 | ) |
|
|
inlinenoexcept |
Decrements expected count by n and waits.
- Precondition
- n must be > 0 and <= the expected count.
- Parameters
-
| n | the value by which the internal counter is decreased. |
◆ CountDown()
| void ion::Latch::CountDown |
( |
std::ptrdiff_t | n = 1 | ) |
|
|
inlinenoexcept |
Decrements expected count by n without waiting.
- Parameters
-
| n | the value by which the internal counter is decreased. |
◆ Max()
| std::ptrdiff_t ion::Latch::Max |
( |
| ) |
|
|
inlinestaticconstexprnoexcept |
- Returns
- Maximum possible value for expected count.
◆ TryWait()
| bool ion::Latch::TryWait |
( |
| ) |
const |
|
inlinenoexcept |
Equivalent to Wait().
- Note
- Method is only provided for conceptual compatibility of
std::latch.
- Returns
- true