[libcxx-commits] [libcxx] 8680feb - [libc++] Use native wait in std::barrier instead of sleep loop (#171041)

via libcxx-commits libcxx-commits at lists.llvm.org
Sun Dec 14 01:35:01 PST 2025


Author: Hui
Date: 2025-12-14T09:34:57Z
New Revision: 8680feb9133e3606943d20beb6f3454171da258a

URL: https://github.com/llvm/llvm-project/commit/8680feb9133e3606943d20beb6f3454171da258a
DIFF: https://github.com/llvm/llvm-project/commit/8680feb9133e3606943d20beb6f3454171da258a.diff

LOG: [libc++] Use native wait in std::barrier instead of sleep loop (#171041)

For some reason, the current `std::barrier`'s wait implementation polls
the underlying atomic in a loop with sleeps instead of using the native
wait.

This change should also indirectly fix the performance issue of
`std::barrier` described in
https://github.com/llvm/llvm-project/issues/123855.

Fixes #123855

Added: 
    

Modified: 
    libcxx/include/barrier

Removed: 
    


################################################################################
diff  --git a/libcxx/include/barrier b/libcxx/include/barrier
index 5f9b471f01741..428a39a44e095 100644
--- a/libcxx/include/barrier
+++ b/libcxx/include/barrier
@@ -57,8 +57,6 @@ namespace std
 #    include <__atomic/memory_order.h>
 #    include <__cstddef/ptr
diff _t.h>
 #    include <__memory/unique_ptr.h>
-#    include <__thread/poll_with_backoff.h>
-#    include <__thread/timed_backoff_policy.h>
 #    include <__utility/move.h>
 #    include <cstdint>
 #    include <limits>
@@ -142,8 +140,7 @@ public:
     return __old_phase;
   }
   _LIBCPP_HIDE_FROM_ABI void wait(arrival_token&& __old_phase) const {
-    auto const __test_fn = [this, __old_phase]() -> bool { return __phase_.load(memory_order_acquire) != __old_phase; };
-    std::__libcpp_thread_poll_with_backoff(__test_fn, __libcpp_timed_backoff_policy());
+    __phase_.wait(__old_phase, std::memory_order_acquire);
   }
   _LIBCPP_HIDE_FROM_ABI void arrive_and_drop() {
     __expected_adjustment_.fetch_sub(1, memory_order_relaxed);


        


More information about the libcxx-commits mailing list