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

via libcxx-commits libcxx-commits at lists.llvm.org
Fri Dec 12 23:55:09 PST 2025


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

>From 19eaea4b84d561edce4e189b1393a508a9cfc65d 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 1/2] [libc++] std::barrier uses native wait

---
 libcxx/include/barrier | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libcxx/include/barrier b/libcxx/include/barrier
index 5f9b471f01741..10d40f32919c8 100644
--- a/libcxx/include/barrier
+++ b/libcxx/include/barrier
@@ -142,8 +142,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);

>From fb6b1362eff391c9e84ea46aca2ede06d513cf44 Mon Sep 17 00:00:00 2001
From: Hui Xie <hui.xie1990 at gmail.com>
Date: Sat, 13 Dec 2025 07:54:58 +0000
Subject: [PATCH 2/2] remove includes

---
 libcxx/include/barrier | 2 --
 1 file changed, 2 deletions(-)

diff --git a/libcxx/include/barrier b/libcxx/include/barrier
index 10d40f32919c8..428a39a44e095 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 <cstdint>
 #    include <limits>



More information about the libcxx-commits mailing list