diff options
| author | Laytan Laats <laytanlaats@hotmail.com> | 2024-08-18 19:31:52 +0200 |
|---|---|---|
| committer | Laytan Laats <laytanlaats@hotmail.com> | 2024-08-18 19:31:52 +0200 |
| commit | b7b3ada3b1bce95d0add13acb8b8192437bad83b (patch) | |
| tree | 968740d692e90f9efabe578c7d959a05c6655bed /src/threading.cpp | |
| parent | f49ebae9562257effe014e3c175496915041d5f2 (diff) | |
UL_COMPARE_AND_WAIT_SHARED is macOS 10.15+
Diffstat (limited to 'src/threading.cpp')
| -rw-r--r-- | src/threading.cpp | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/src/threading.cpp b/src/threading.cpp index 011b66028..e30a20a06 100644 --- a/src/threading.cpp +++ b/src/threading.cpp @@ -839,8 +839,16 @@ gb_internal void futex_signal(Futex *f) { } } else { #endif + // UL_COMPARE_AND_WAIT_SHARED is only available on macOS 10.15+ + int WAIT_FLAG; + if (__builtin_available(macOS 10.15, *)) { + WAIT_FLAG = UL_COMPARE_AND_WAIT_SHARED; + } else { + WAIT_FLAG = UL_COMPARE_AND_WAIT; + } + for (;;) { - int ret = __ulock_wake(UL_COMPARE_AND_WAIT_SHARED | ULF_NO_ERRNO, f, 0); + int ret = __ulock_wake(WAIT_FLAG | ULF_NO_ERRNO, f, 0); if (ret >= 0) { return; } @@ -875,9 +883,17 @@ gb_internal void futex_broadcast(Futex *f) { } } else { #endif + // UL_COMPARE_AND_WAIT_SHARED is only available on macOS 10.15+ + int WAIT_FLAG; + if (__builtin_available(macOS 10.15, *)) { + WAIT_FLAG = UL_COMPARE_AND_WAIT_SHARED; + } else { + WAIT_FLAG = UL_COMPARE_AND_WAIT; + } + for (;;) { enum { ULF_WAKE_ALL = 0x00000100 }; - int ret = __ulock_wake(UL_COMPARE_AND_WAIT_SHARED | ULF_NO_ERRNO | ULF_WAKE_ALL, f, 0); + int ret = __ulock_wake(WAIT_FLAG | ULF_NO_ERRNO | ULF_WAKE_ALL, f, 0); if (ret == 0) { return; } @@ -915,8 +931,16 @@ gb_internal void futex_wait(Futex *f, Footex val) { } } else { #endif + // UL_COMPARE_AND_WAIT_SHARED is only available on macOS 10.15+ + int WAIT_FLAG; + if (__builtin_available(macOS 10.15, *)) { + WAIT_FLAG = UL_COMPARE_AND_WAIT_SHARED; + } else { + WAIT_FLAG = UL_COMPARE_AND_WAIT; + } + for (;;) { - int ret = __ulock_wait(UL_COMPARE_AND_WAIT_SHARED | ULF_NO_ERRNO, f, val, 0); + int ret = __ulock_wait(WAIT_FLAG | ULF_NO_ERRNO, f, val, 0); if (ret >= 0) { if (*f != val) { return; |