diff --git a/core/sync/sync2/futex_darwin.odin b/core/sync/sync2/futex_darwin.odin index 6e56178e4..f20ba73a6 100644 --- a/core/sync/sync2/futex_darwin.odin +++ b/core/sync/sync2/futex_darwin.odin @@ -23,26 +23,26 @@ EINTR :: -4 EFAULT :: -14 ETIMEDOUT :: -60 -_futex_wait :: proc(f: ^Futex, expected: u32) -> Futex_Error { +_futex_wait :: proc(f: ^Futex, expected: u32) -> bool { return _futex_wait_with_timeout(f, expected, 0) } -_futex_wait_with_timeout :: proc(f: ^Futex, expected: u32, duration: time.Duration) -> Futex_Error { +_futex_wait_with_timeout :: proc(f: ^Futex, expected: u32, duration: time.Duration) -> bool { timeout_ns := u64(duration) s := __ulock_wait2(UL_COMPARE_AND_WAIT | ULF_NO_ERRNO, f, u64(expected), timeout_ns, 0) if s >= 0 { - return nil + return true } switch s { case EINTR, EFAULT: - return nil + return true case ETIMEDOUT: - return .Timed_Out + return false case: panic("futex_wait failure") } - return nil + return true } diff --git a/core/sync/sync2/futex_linux.odin b/core/sync/sync2/futex_linux.odin index 9fadd4c06..6ee5ff2b1 100644 --- a/core/sync/sync2/futex_linux.odin +++ b/core/sync/sync2/futex_linux.odin @@ -39,22 +39,22 @@ internal_futex :: proc(f: ^Futex, op: c.int, val: u32, timeout: rawptr) -> int { } -_futex_wait :: proc(f: ^Futex, expected: u32) -> Futex_Error { +_futex_wait :: proc(f: ^Futex, expected: u32) -> bool { err := internal_futex(f, FUTEX_WAIT_PRIVATE | FUTEX_WAIT, expected, nil) switch err { case ESUCCESS, EINTR, EAGAIN, EINVAL: // okay case ETIMEDOUT: - return .Timed_Out + return false case EFAULT: fallthrough case: panic("futex_wait failure") } - return nil + return true } -_futex_wait_with_timeout :: proc(f: ^Futex, expected: u32, duration: time.Duration) -> Futex_Error { +_futex_wait_with_timeout :: proc(f: ^Futex, expected: u32, duration: time.Duration) -> bool { timespec_t :: struct { tv_sec: c.long, tv_nsec: c.long, @@ -74,13 +74,13 @@ _futex_wait_with_timeout :: proc(f: ^Futex, expected: u32, duration: time.Durati case ESUCCESS, EINTR, EAGAIN, EINVAL: // okay case ETIMEDOUT: - return .Timed_Out + return false case EFAULT: fallthrough case: panic("futex_wait_with_timeout failure") } - return nil + return true } diff --git a/core/sync/sync2/futex_windows.odin b/core/sync/sync2/futex_windows.odin index 361c2bc3f..63772d78e 100644 --- a/core/sync/sync2/futex_windows.odin +++ b/core/sync/sync2/futex_windows.odin @@ -20,13 +20,13 @@ foreign Synchronization { -_futex_wait :: proc(f: ^Futex, expect: u32) -> Futex_Error { +_futex_wait :: proc(f: ^Futex, expect: u32) -> bool { expect := expect ok := RtlWaitOnAddress(f, &expect, size_of(expect), nil) - return nil if ok else .Timed_Out + return bool(ok) } -_futex_wait_with_timeout :: proc(f: ^Futex, expect: u32, duration: time.Duration) -> Futex_Error { +_futex_wait_with_timeout :: proc(f: ^Futex, expect: u32, duration: time.Duration) -> bool { expect := expect timeout: i64 @@ -38,7 +38,7 @@ _futex_wait_with_timeout :: proc(f: ^Futex, expect: u32, duration: time.Duration } \ ok := RtlWaitOnAddress(f, &expect, size_of(expect), timeout_ptr) - return nil if ok else .Timed_Out + return bool(ok) } _futex_wake_single :: proc(f: ^Futex) { diff --git a/core/sync/sync2/primitives.odin b/core/sync/sync2/primitives.odin index 230a8b0d4..81bd1ba73 100644 --- a/core/sync/sync2/primitives.odin +++ b/core/sync/sync2/primitives.odin @@ -202,25 +202,21 @@ sema_post :: proc(s: ^Sema, count := 1) { // An Futex must not be copied after first use Futex :: distinct u32 -Futex_Error :: enum { - None, - Timed_Out, -} - futex_wait :: proc(f: ^Futex, expected: u32) { if u32(atomic_load(f)) != expected { return } - assert(_futex_wait(f, expected) != nil, "futex_wait failure") + assert(_futex_wait(f, expected), "futex_wait failure") } -futex_wait_with_timeout :: proc(f: ^Futex, expected: u32, duration: time.Duration) -> Futex_Error { +// returns true if the wait happened within the duration, false if it exceeded the time duration +futex_wait_with_timeout :: proc(f: ^Futex, expected: u32, duration: time.Duration) -> bool { if u32(atomic_load(f)) != expected { - return nil + return true } if duration == 0 { - return .Timed_Out + return false } return _futex_wait_with_timeout(f, expected, duration) diff --git a/core/sync/sync2/primitives_atomic.odin b/core/sync/sync2/primitives_atomic.odin index 94db980a5..1aee76020 100644 --- a/core/sync/sync2/primitives_atomic.odin +++ b/core/sync/sync2/primitives_atomic.odin @@ -307,7 +307,7 @@ queue_item_wait_with_timeout :: proc(item: ^Queue_Item, duration: time.Duration) if remaining < 0 { return false } - if futex_wait_with_timeout(&item.futex, 0, remaining) == .Timed_Out { + if !futex_wait_with_timeout(&item.futex, 0, remaining) { return false } cpu_relax()