5#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_SYNCHRONIZATION_LATCH_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_SYNCHRONIZATION_LATCH_HPP_
13#include "arene/base/compiler_support/expect.hpp"
14#include "arene/base/contracts.hpp"
15#include "arene/base/synchronization/manual_reset_event.hpp"
32 static constexpr auto max()
noexcept ->
std::
ptrdiff_t {
return std::numeric_limits<std::ptrdiff_t>::max(); }
39 constexpr explicit latch(std::ptrdiff_t initial_count)
41 ARENE_PRECONDITION(initial_count >= 0);
61 auto try_wait()
const noexcept ->
bool {
return count_.load(std::memory_order_acquire) == 0; }
71 ARENE_PRECONDITION((update >= 0) && (update <= count_));
72 if (count_.fetch_sub(update, std::memory_order_acq_rel) == update) {
109 std::atomic<std::ptrdiff_t> count_;
111 manual_reset_event event_;
Backport of std::latch from C++20. Provides a count-down latch that stays permanently signalled when ...
Definition latch.hpp:28
auto try_wait() const noexcept -> bool
Check if the latch is signalled without blocking.
Definition latch.hpp:61
void count_down()
Count down the latch by 1. If the counter reaches zero, the latch is permanently signalled,...
Definition latch.hpp:83
auto operator=(latch const &) -> latch &=delete
Not copyable.
latch(latch const &)=delete
Not copyable.
auto operator=(latch &&) -> latch &=delete
Not movable.
void arrive_and_wait()
Count down the latch by 1 and blocks the current thread waiting for the latch to be signalled.
Definition latch.hpp:105
static constexpr auto max() noexcept -> std::ptrdiff_t
Get the maximum supported count.
Definition latch.hpp:32
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 sign...
Definition latch.hpp:39
~latch()=default
Default destructor.
void count_down(std::ptrdiff_t update)
Count down the latch by update. If the counter reaches zero, the latch is permanently signalled,...
Definition latch.hpp:70
void wait() const
Blocks the current thread until the latch becomes signalled.
Definition latch.hpp:87
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.
Definition latch.hpp:97
latch(latch &&)=delete
Not movable.
Definition array_exceptions_disabled.cpp:11
Copyright 2026, Toyota Motor Corporation.
Definition array_exceptions_disabled.cpp:10