Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
arene::base::latch Class Reference

Backport of std::latch from C++20. Provides a count-down latch that stays permanently signalled when the count reaches zero. For a given instance, every call to count_down or arrive_and_wait synchronizes-with every call to wait or arrive_and_wait, and every call to try_wait that returns true. More...

Public Member Functions

 latch (latch &&)=delete
 Not movable.
 
 latch (latch const &)=delete
 Not copyable.
 
constexpr latch (std::ptrdiff_t initial_count)
 Construct a latch with the specified count. If the count is zero, then the latch will be already signalled.
 
 ~latch ()=default
 Default destructor.
 
void arrive_and_wait ()
 Count down the latch by 1 and blocks the current thread waiting for the latch to be signalled.
 
void arrive_and_wait (std::ptrdiff_t const update)
 Count down the latch by update and blocks the current thread waiting for the latch to be signalled.
 
void count_down ()
 Count down the latch by 1. If the counter reaches zero, the latch is permanently signalled, and any threads blocked in wait are unblocked.
 
void count_down (std::ptrdiff_t update)
 Count down the latch by update. If the counter reaches zero, the latch is permanently signalled, and any threads blocked in wait are unblocked.
 
auto operator= (latch &&) -> latch &=delete
 Not movable.
 
auto operator= (latch const &) -> latch &=delete
 Not copyable.
 
auto try_wait () const noexcept -> bool
 Check if the latch is signalled without blocking.
 
void wait () const
 Blocks the current thread until the latch becomes signalled.
 

Static Public Member Functions

static constexpr auto max () noexcept -> std::ptrdiff_t
 Get the maximum supported count.
 

Detailed Description

Backport of std::latch from C++20. Provides a count-down latch that stays permanently signalled when the count reaches zero. For a given instance, every call to count_down or arrive_and_wait synchronizes-with every call to wait or arrive_and_wait, and every call to try_wait that returns true.

Constructor & Destructor Documentation

◆ latch() [1/3]

arene::base::latch::latch ( std::ptrdiff_t initial_count)
inlineexplicitconstexpr

Construct a latch with the specified count. If the count is zero, then the latch will be already signalled.

Parameters
initial_countThe initial count for the latch
Precondition
initial_count >= 0

◆ ~latch()

arene::base::latch::~latch ( )
default

Default destructor.

◆ latch() [2/3]

arene::base::latch::latch ( latch const & )
delete

Not copyable.

◆ latch() [3/3]

arene::base::latch::latch ( latch && )
delete

Not movable.

Member Function Documentation

◆ arrive_and_wait() [1/2]

void arene::base::latch::arrive_and_wait ( )
inline

Count down the latch by 1 and blocks the current thread waiting for the latch to be signalled.

Exceptions
std::system_erroron error

◆ arrive_and_wait() [2/2]

void arene::base::latch::arrive_and_wait ( std::ptrdiff_t const update)
inline

Count down the latch by update and blocks the current thread waiting for the latch to be signalled.

Parameters
updateThe amount by which to decrease the count
Exceptions
std::system_erroron error

◆ count_down() [1/2]

void arene::base::latch::count_down ( )
inline

Count down the latch by 1. If the counter reaches zero, the latch is permanently signalled, and any threads blocked in wait are unblocked.

Precondition
The latch must not be signalled.
Exceptions
std::system_erroron error

◆ count_down() [2/2]

void arene::base::latch::count_down ( std::ptrdiff_t update)
inline

Count down the latch by update. If the counter reaches zero, the latch is permanently signalled, and any threads blocked in wait are unblocked.

Parameters
updateThe amount by which to decrease the count
Precondition
(update >= 0) && (update <= count_)
Exceptions
std::system_erroron error

◆ max()

static constexpr auto arene::base::latch::max ( ) -> std::ptrdiff_t
inlinestaticconstexprnoexcept

Get the maximum supported count.

Returns
The maximum count

◆ operator=() [1/2]

auto arene::base::latch::operator= ( latch && ) -> latch &=delete
delete

Not movable.

◆ operator=() [2/2]

auto arene::base::latch::operator= ( latch const & ) -> latch &=delete
delete

Not copyable.

◆ try_wait()

auto arene::base::latch::try_wait ( ) const -> bool
inlinenoexcept

Check if the latch is signalled without blocking.

Returns
true if the latch is signalled, false otherwise.

◆ wait()

void arene::base::latch::wait ( ) const
inline

Blocks the current thread until the latch becomes signalled.

Exceptions
std::system_erroron error

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