2#include <asyncpp/event.h>
19 static constexpr std::size_t
max = std::numeric_limits<std::size_t>::max();
25 explicit latch(std::size_t initial) noexcept : m_count{initial}, m_event{initial <= 0} {}
42 if (m_count.fetch_sub(n, std::memory_order::acq_rel) == 0) { m_event.
set(); }
54 return m_event.
wait(resume_dispatcher);
58 std::atomic<std::size_t> m_count;
Basic dispatcher interface class.
Definition dispatcher.h:8
static dispatcher * current() noexcept
Definition dispatcher.h:48
The latch class is a downward counter of type std::size_t which can be used to synchronize coroutines...
Definition latch.h:16
static constexpr std::size_t max
The maximum value of counter supported.
Definition latch.h:19
void decrement(std::size_t n=1) noexcept
Decrement the latch counter.
Definition latch.h:41
latch(const latch &)=delete
latch is not copyable
bool is_ready() const noexcept
Check if the latch reached zero.
Definition latch.h:34
latch(std::size_t initial) noexcept
Constructs a latch and initializes its internal counter.
Definition latch.h:25
latch & operator=(const latch &)=delete
latch is not copyable
auto wait(dispatcher *resume_dispatcher=nullptr) noexcept
Wait for the counter to reach zero.
Definition latch.h:53
Simple manual reset event supporting multiple consumers.
Definition event.h:306
bool set(dispatcher *resume_dispatcher=nullptr) noexcept
Set the event.
Definition event.h:339
bool is_set() const noexcept
Query if the event is currently set.
Definition event.h:322
constexpr auto wait(dispatcher *resume_dispatcher=nullptr) noexcept
Suspend the current coroutine until the event is set.
Definition event.h:387