From 8680feb9133e3606943d20beb6f3454171da258a Mon Sep 17 00:00:00 2001 From: Hui Date: Sun, 14 Dec 2025 09:34:57 +0000 Subject: [PATCH] [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 --- libcxx/include/barrier | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/libcxx/include/barrier b/libcxx/include/barrier index 5f9b471f0174..428a39a44e09 100644 --- a/libcxx/include/barrier +++ b/libcxx/include/barrier @@ -57,8 +57,6 @@ namespace std # include <__atomic/memory_order.h> # include <__cstddef/ptrdiff_t.h> # include <__memory/unique_ptr.h> -# include <__thread/poll_with_backoff.h> -# include <__thread/timed_backoff_policy.h> # include <__utility/move.h> # include # include @@ -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);