19#include <ion/detail/macros.hpp>
52 inline constexpr explicit Latch(std::ptrdiff_t expected)
noexcept;
67 inline void CountDown(std::ptrdiff_t n = 1)
noexcept;
76 inline bool TryWait()
const noexcept;
81 inline void Wait()
const noexcept;
93 inline static constexpr std::ptrdiff_t
Max()
noexcept;
97 ION_FORCE_INLINE
inline bool Arrive(std::ptrdiff_t n)
noexcept;
102 std::atomic<std::ptrdiff_t> m_remaining;
105constexpr Latch::Latch(std::ptrdiff_t expected) noexcept : m_remaining(expected) {
106 assert(expected >= 0 && expected <=
Max());
109bool Latch::Arrive(std::ptrdiff_t n)
noexcept {
111 return m_remaining.fetch_sub(n, std::memory_order_release) == n;
120 auto remaining = m_remaining.load(std::memory_order_relaxed);
121 if (remaining == 0) {
123 std::atomic_thread_fence(std::memory_order_acquire);
136 return std::numeric_limits<std::ptrdiff_t>::max();
143 std::atomic_thread_fence(std::memory_order_acquire);
void CountDown(std::ptrdiff_t n=1) noexcept
Decrements expected count by n without waiting.
Definition latch.hpp:114
static constexpr std::ptrdiff_t Max() noexcept
Definition latch.hpp:135
bool TryWait() const noexcept
Equivalent to Wait().
Definition latch.hpp:130
void ArriveAndWait(std::ptrdiff_t n=1) noexcept
Decrements expected count by n and waits.
Definition latch.hpp:139
constexpr Latch(std::ptrdiff_t expected) noexcept
Construct latch with expected number of arrivals.
Definition latch.hpp:105
void Wait() const noexcept
Block until expected count reaches zero.
Definition latch.hpp:118
auto Wait(SignalToken< T > &token) noexcept -> T
Wait until signal source changes and return current value.