Skip to content

Commit b9d8d1e

Browse files
authored
[libc++][NFC] atomic::wait use public API on macOS (#147146)
At the moment, we use the os internal functions `__ulock_wait`. This patch updates the code on macOS to use the public API `os_sync_wait_on_address`. Fixes #146142
1 parent 9adc8dd commit b9d8d1e

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

libcxx/src/atomic.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@
4141
// OpenBSD has no indirect syscalls
4242
# define _LIBCPP_FUTEX(...) futex(__VA_ARGS__)
4343

44+
#elif defined(__APPLE__) && defined(_LIBCPP_USE_ULOCK)
45+
46+
# include <os/os_sync_wait_on_address.h>
47+
4448
#else // <- Add other operating systems here
4549

4650
// Baseline needs no new headers
@@ -65,24 +69,15 @@ static void __libcpp_platform_wake_by_address(__cxx_atomic_contention_t const vo
6569

6670
#elif defined(__APPLE__) && defined(_LIBCPP_USE_ULOCK)
6771

68-
extern "C" int __ulock_wait(
69-
uint32_t operation, void* addr, uint64_t value, uint32_t timeout); /* timeout is specified in microseconds */
70-
extern "C" int __ulock_wake(uint32_t operation, void* addr, uint64_t wake_value);
71-
72-
// https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/bsd/sys/ulock.h#L82
73-
# define UL_COMPARE_AND_WAIT64 5
74-
# define ULF_WAKE_ALL 0x00000100
75-
7672
static void
7773
__libcpp_platform_wait_on_address(__cxx_atomic_contention_t const volatile* __ptr, __cxx_contention_t __val) {
7874
static_assert(sizeof(__cxx_atomic_contention_t) == 8, "Waiting on 8 bytes value");
79-
__ulock_wait(UL_COMPARE_AND_WAIT64, const_cast<__cxx_atomic_contention_t*>(__ptr), __val, 0);
75+
os_sync_wait_on_address(const_cast<__cxx_atomic_contention_t*>(__ptr), __val, 8, OS_SYNC_WAIT_ON_ADDRESS_NONE);
8076
}
8177

8278
static void __libcpp_platform_wake_by_address(__cxx_atomic_contention_t const volatile* __ptr, bool __notify_one) {
8379
static_assert(sizeof(__cxx_atomic_contention_t) == 8, "Waking up on 8 bytes value");
84-
__ulock_wake(
85-
UL_COMPARE_AND_WAIT64 | (__notify_one ? 0 : ULF_WAKE_ALL), const_cast<__cxx_atomic_contention_t*>(__ptr), 0);
80+
os_sync_wake_by_address_all(const_cast<__cxx_atomic_contention_t*>(__ptr), 8, OS_SYNC_WAKE_BY_ADDRESS_NONE);
8681
}
8782

8883
#elif defined(__FreeBSD__) && __SIZEOF_LONG__ == 8

0 commit comments

Comments
 (0)