[libcxx-commits] [libcxx] [libc++] std::barrier uses native wait (PR #171041)

via libcxx-commits libcxx-commits at lists.llvm.org
Sun Dec 7 06:49:53 PST 2025


https://github.com/huixie90 created https://github.com/llvm/llvm-project/pull/171041

None

>From 6ce071ddc3271dd92fdffafea4a079128bf591b8 Mon Sep 17 00:00:00 2001
From: Hui Xie <hui.xie1990 at gmail.com>
Date: Sun, 7 Dec 2025 14:49:00 +0000
Subject: [PATCH] [libc++] std::barrier uses native wait

---
 libcxx/include/barrier | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libcxx/include/barrier b/libcxx/include/barrier
index 5f9b471f01741..a997152cb5a5d 100644
--- a/libcxx/include/barrier
+++ b/libcxx/include/barrier
@@ -54,6 +54,7 @@ namespace std
 
 #    include <__assert>
 #    include <__atomic/atomic.h>
+#    include <__atomic/atomic_sync.h>
 #    include <__atomic/memory_order.h>
 #    include <__cstddef/ptrdiff_t.h>
 #    include <__memory/unique_ptr.h>
@@ -142,8 +143,9 @@ 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());
+    std::__atomic_wait_unless(__phase_, memory_order_acquire, [this, &__old_phase](arrival_token& __value) -> bool {
+      return __old_phase != __value;
+    });
   }
   _LIBCPP_HIDE_FROM_ABI void arrive_and_drop() {
     __expected_adjustment_.fetch_sub(1, memory_order_relaxed);



More information about the libcxx-commits mailing list