From 0975820c48f8e876c2838a5ef94400fdb5db0f87 Mon Sep 17 00:00:00 2001 From: Laytan Laats Date: Tue, 17 Sep 2024 15:52:35 +0200 Subject: [PATCH] fix wrong ulock timeout calculation, add version check for ios --- core/sync/futex_darwin.odin | 5 ++++- core/sys/darwin/sync.odin | 8 ++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/core/sync/futex_darwin.odin b/core/sync/futex_darwin.odin index 32fdb1552..87b7b96e6 100644 --- a/core/sync/futex_darwin.odin +++ b/core/sync/futex_darwin.odin @@ -12,6 +12,7 @@ foreign System { // __ulock_wait is not available on 10.15 // See https://github.com/odin-lang/Odin/issues/1959 __ulock_wait :: proc "c" (operation: u32, addr: rawptr, value: u64, timeout_us: u32) -> c.int --- + // >= MacOS 11. __ulock_wait2 :: proc "c" (operation: u32, addr: rawptr, value: u64, timeout_ns: u64, value2: u64) -> c.int --- __ulock_wake :: proc "c" (operation: u32, addr: rawptr, wake_value: u64) -> c.int --- } @@ -57,12 +58,14 @@ _futex_wait_with_timeout :: proc "contextless" (f: ^Futex, expected: u32, durati timeout_ns := u64(duration) s := __ulock_wait2(UL_COMPARE_AND_WAIT | ULF_NO_ERRNO, f, u64(expected), timeout_ns, 0) } else { - timeout_us := u32(duration) * 1000 + timeout_us := u32(duration / time.Microsecond) s := __ulock_wait(UL_COMPARE_AND_WAIT | ULF_NO_ERRNO, f, u64(expected), timeout_us) } + if s >= 0 { return true } + switch s { case EINTR, EFAULT: return true diff --git a/core/sys/darwin/sync.odin b/core/sys/darwin/sync.odin index e90f30162..58fc7c9e4 100644 --- a/core/sys/darwin/sync.odin +++ b/core/sys/darwin/sync.odin @@ -5,6 +5,7 @@ foreign import system "system:System.framework" // #define OS_WAIT_ON_ADDR_AVAILABILITY \ // __API_AVAILABLE(macos(14.4), ios(17.4), tvos(17.4), watchos(10.4)) when ODIN_OS == .Darwin { + when ODIN_PLATFORM_SUBTARGET == .iOS && ODIN_MINIMUM_OS_VERSION >= 17_04_00 { WAIT_ON_ADDRESS_AVAILABLE :: true } else when ODIN_MINIMUM_OS_VERSION >= 14_04_00 { @@ -12,7 +13,10 @@ when ODIN_OS == .Darwin { } else { WAIT_ON_ADDRESS_AVAILABLE :: false } - when ODIN_MINIMUM_OS_VERSION >= 11_00_00 { + + when ODIN_PLATFORM_SUBTARGET == .iOS && ODIN_MINIMUM_OS_VERSION >= 14_00_00 { + ULOCK_WAIT_2_AVAILABLE :: true + } else when ODIN_MINIMUM_OS_VERSION >= 11_00_00 { ULOCK_WAIT_2_AVAILABLE :: true } else { ULOCK_WAIT_2_AVAILABLE :: false @@ -20,7 +24,7 @@ when ODIN_OS == .Darwin { } else { WAIT_ON_ADDRESS_AVAILABLE :: false - ULOCK_WAIT_2_AVAILABLE :: false + ULOCK_WAIT_2_AVAILABLE :: false } os_sync_wait_on_address_flag :: enum u32 {