30#define _GLIBCXX_LATCH 1
32#pragma GCC system_header
36#define __glibcxx_want_latch
43namespace std _GLIBCXX_VISIBILITY(default)
45_GLIBCXX_BEGIN_NAMESPACE_VERSION
50 static constexpr ptrdiff_t
54 constexpr explicit latch(ptrdiff_t __expected) noexcept
55 : _M_a(__expected) { }
58 latch(
const latch&) =
delete;
59 latch& operator=(
const latch&) =
delete;
61 _GLIBCXX_ALWAYS_INLINE
void
62 count_down(ptrdiff_t __update = 1)
64 auto const __old = __atomic_impl::fetch_sub(&_M_a,
65 __update, memory_order::release);
66 if (__old == __update)
67 __atomic_impl::notify_all(&_M_a);
70 _GLIBCXX_ALWAYS_INLINE
bool
71 try_wait() const noexcept
72 {
return __atomic_impl::load(&_M_a, memory_order::acquire) == 0; }
74 _GLIBCXX_ALWAYS_INLINE
void
77 auto const __pred = [
this] {
return this->try_wait(); };
78 std::__atomic_wait_address(&_M_a, __pred);
81 _GLIBCXX_ALWAYS_INLINE
void
82 arrive_and_wait(ptrdiff_t __update = 1) noexcept
89 alignas(__alignof__(__detail::__platform_wait_t)) __detail::__platform_wait_t _M_a;
91_GLIBCXX_END_NAMESPACE_VERSION
ISO C++ entities toplevel namespace is std.
__numeric_traits_integer< _Tp > __int_traits
Convenience alias for __numeric_traits<integer-type>.