[libcxx-commits] [libcxx] [libc++] atomic timed wait (PR #172214)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Fri Dec 19 11:08:58 PST 2025


================
@@ -117,11 +128,20 @@ static void __platform_wake_by_address(void const* __ptr, bool __notify_one) {
  */
 
 template <std::size_t _Size>
-static void __platform_wait_on_address(void const* __ptr, void const* __val) {
+static void __platform_wait_on_address(void const* __ptr, void const* __val, uint64_t __timeout_ns) {
   static_assert(_Size == 8, "Can only wait on 8 bytes value");
-  char buffer[_Size];
-  std::memcpy(&buffer, const_cast<const void*>(__val), _Size);
-  _umtx_op(const_cast<void*>(__ptr), UMTX_OP_WAIT, *reinterpret_cast<__cxx_contention_t*>(&buffer), nullptr, nullptr);
+  if (__timeout_ns == 0) {
+    char buffer[_Size];
+    std::memcpy(&buffer, const_cast<const void*>(__val), _Size);
+    _umtx_op(const_cast<void*>(__ptr), UMTX_OP_WAIT, *reinterpret_cast<__cxx_contention_t*>(&buffer), nullptr, nullptr);
+  } else {
+    // TODO the doc says it supports timeout but does not say how to use it
+    // https://man.freebsd.org/cgi/man.cgi?query=_umtx_op
----------------
ldionne wrote:

@emaste Can you help us figure out how to use this API with a timeout? Nothing seems to say how to actually pass the timeout.

https://github.com/llvm/llvm-project/pull/172214


More information about the libcxx-commits mailing list