Async++ unknown
Async (co_await/co_return) code for C++
Loading...
Searching...
No Matches
asyncpp::latch Class Reference

The latch class is a downward counter of type std::size_t which can be used to synchronize coroutines. More...

#include <asyncpp/latch.h>

Public Member Functions

 latch (std::size_t initial) noexcept
 Constructs a latch and initializes its internal counter.
 
 latch (const latch &)=delete
 latch is not copyable
 
latchoperator= (const latch &)=delete
 latch is not copyable
 
bool is_ready () const noexcept
 Check if the latch reached zero.
 
void decrement (std::size_t n=1) noexcept
 Decrement the latch counter.
 
auto operator co_await () noexcept
 Wait for the counter to reach zero.
 
auto wait (dispatcher *resume_dispatcher=nullptr) noexcept
 Wait for the counter to reach zero.
 

Static Public Attributes

static constexpr std::size_t max = std::numeric_limits<std::size_t>::max()
 The maximum value of counter supported.
 

Detailed Description

The latch class is a downward counter of type std::size_t which can be used to synchronize coroutines.

The value of the counter is initialized on creation. Threads may block on the latch until the counter is decremented to zero. There is no possibility to increase or reset the counter, which makes the latch a single-use barrier. Concurrent invocations of the member functions of latch, except for the destructor, do not introduce data races.

Constructor & Destructor Documentation

◆ latch()

asyncpp::latch::latch ( std::size_t initial)
inlineexplicitnoexcept

Constructs a latch and initializes its internal counter.

Parameters
initialThe initial counter value

Member Function Documentation

◆ decrement()

void asyncpp::latch::decrement ( std::size_t n = 1)
inlinenoexcept

Decrement the latch counter.

Parameters
nAmount to decrement from the counter
Note
It is undefined if the sum of all decrement calls exceeds the counter value.

The documentation for this class was generated from the following file: