[10/10] libstdc++: Optimise std::latch::arrive_and_wait

Message ID 20250110212810.832494-11-jwakely@redhat.com
State New
Headers
Series C++20 atomic wait/notify ABI stabilization |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gcc_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gcc_check--master-aarch64 fail Test failed
linaro-tcwg-bot/tcwg_gcc_check--master-arm fail Test failed

Commit Message

Jonathan Wakely Jan. 10, 2025, 9:23 p.m. UTC
  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(+)
  

Patch

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: