[libcxx-commits] [libcxx] [libc++] Use public os_sync API instead of private __ulock on newer Apple platforms (PR #182947)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Fri Mar 13 10:40:55 PDT 2026


================
@@ -90,6 +95,30 @@ static void __platform_wake_by_address(void const* __ptr, bool __notify_one) {
   _LIBCPP_FUTEX(__ptr, FUTEX_WAKE_PRIVATE, __notify_one ? 1 : INT_MAX, 0, 0, 0);
 }
 
+#elif defined(__APPLE__) && defined(_LIBCPP_USE_OS_SYNC)
+
+template <std::size_t _Size, class MaybeTimeout>
+static void __platform_wait_on_address(void const* __ptr, void const* __val, MaybeTimeout maybe_timeout_ns) {
+  static_assert(_Size == 8 || _Size == 4, "Can only wait on 8 bytes or 4 bytes value");
+  uint64_t __value = 0;
+  std::memcpy(&__value, __val, _Size);
----------------
ldionne wrote:

I would suggest doing this, which is IMO the clearest approach (and in this case, clearest == simplest == best):

```c++
uint64_t __value = []() -> uint64_t {
  if constexpr (_Size == 4) {
    std::uint32_t result;
    std::memcpy(&result, __val, _Size);
    return result;
  } else if constexpr (_Size == 8) {
    std::uint64_t result;
    std::memcpy(&result, __val, _Size);
    return result;
  } else {
    static_assert(false, "Can only wait on 8 bytes or 4 bytes value");
  }
}();
```

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


More information about the libcxx-commits mailing list