mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-10 05:11:37 -07:00
Remove import cycle on FreeBSD
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user