diff options
| author | gingerBill <bill@gingerbill.org> | 2022-07-18 15:20:28 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2022-07-18 15:20:28 +0100 |
| commit | 9eb3da0474c7e00d0c246dc60409cf86f7db4e51 (patch) | |
| tree | 03b97eaf32382e79411ead79425c613c90b30f2e /core/sync | |
| parent | e91f8feedfec3316c93e32172d4c0ae989776b32 (diff) | |
Remove import cycle on FreeBSD
Diffstat (limited to 'core/sync')
| -rw-r--r-- | core/sync/futex_freebsd.odin | 20 | ||||
| -rw-r--r-- | core/sync/primitives_freebsd.odin | 10 |
2 files changed, 16 insertions, 14 deletions
diff --git a/core/sync/futex_freebsd.odin b/core/sync/futex_freebsd.odin index 2e1d065bc..07fba82a8 100644 --- a/core/sync/futex_freebsd.odin +++ b/core/sync/futex_freebsd.odin @@ -3,24 +3,22 @@ package sync import "core:c" -import "core:os" import "core:time" UMTX_OP_WAIT :: 2 UMTX_OP_WAKE :: 3 +ETIMEDOUT :: 60 + foreign import libc "system:c" foreign libc { _umtx_op :: proc "c" (obj: rawptr, op: c.int, val: c.ulong, uaddr: rawptr, uaddr2: rawptr) -> c.int --- + __error :: proc "c" () -> ^c.int --- } _futex_wait :: proc(f: ^Futex, expected: u32) -> bool { - timeout := os.Unix_File_Time{ - seconds = 5, - nanoseconds = 0, - } - + timeout := [2]i64{14400, 0} // 4 hours for { res := _umtx_op(f, UMTX_OP_WAIT, c.ulong(expected), nil, &timeout) @@ -28,7 +26,7 @@ _futex_wait :: proc(f: ^Futex, expected: u32) -> bool { return true } - if os.Errno(os.get_last_error()) == os.ETIMEDOUT { + if __error()^ == ETIMEDOUT { continue } @@ -42,16 +40,14 @@ _futex_wait_with_timeout :: proc(f: ^Futex, expected: u32, duration: time.Durati return false } - res := _umtx_op(f, UMTX_OP_WAIT, c.ulong(expected), nil, &os.Unix_File_Time{ - seconds = (os.time_t)(duration/1e9), - nanoseconds = (c.long)(duration%1e9), - }) + timeout := [2]i64{i64(duration/1e9), i64(duration%1e9)} + res := _umtx_op(f, UMTX_OP_WAIT, c.ulong(expected), nil, &timeout) if res != -1 { return true } - if os.Errno(os.get_last_error()) == os.ETIMEDOUT { + if __error()^ == ETIMEDOUT { return false } diff --git a/core/sync/primitives_freebsd.odin b/core/sync/primitives_freebsd.odin index e6219acf1..2d7cbf18d 100644 --- a/core/sync/primitives_freebsd.odin +++ b/core/sync/primitives_freebsd.odin @@ -2,8 +2,14 @@ //+private package sync -import "core:os" +import "core:c" + +foreign import dl "system:dl" + +foreign dl { + pthread_getthreadid_np :: proc "c" () -> c.int --- +} _current_thread_id :: proc "contextless" () -> int { - return os.current_thread_id() + return int(pthread_getthreadid_np()) } |