We don't need to wait if we know the counter has reached zero. libstdc++-v3/ChangeLog:
* include/std/latch (latch::arrive_and_wait): Optimise. --- This one's commented out for now, but sending for review anyway. libstdc++-v3/include/std/latch | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libstdc++-v3/include/std/latch b/libstdc++-v3/include/std/latch index 8bdf68f3390a..af24dd081e04 100644 --- a/libstdc++-v3/include/std/latch +++ b/libstdc++-v3/include/std/latch @@ -101,8 +101,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _GLIBCXX_ALWAYS_INLINE void arrive_and_wait(ptrdiff_t __update = 1) noexcept { +#if 0 + __glibcxx_assert(__update >= 0 && __update <= max()); + auto const __old = __atomic_impl::fetch_sub(&_M_a, __update, + memory_order::release); + if (std::cmp_equal(__old, __update)) + __atomic_impl::notify_all(&_M_a); + else if (std::cmp_greater(__old, __update)) + wait(); + else + __glibcxx_assert(std::cmp_less_equal(__update, __old)); +#else count_down(__update); wait(); +#endif } private: -- 2.47.1