Clean up _futex_wait_with_timeout on Linux

This commit is contained in:
gingerBill
2021-10-11 19:49:56 +01:00
parent 077bf28d26
commit 310fd1936b
+8 -10
View File
@@ -55,21 +55,19 @@ _futex_wait :: proc(f: ^Futex, expected: u32) -> bool {
} }
_futex_wait_with_timeout :: proc(f: ^Futex, expected: u32, duration: time.Duration) -> bool { _futex_wait_with_timeout :: proc(f: ^Futex, expected: u32, duration: time.Duration) -> bool {
if duration <= 0 {
return false
}
timespec_t :: struct { timespec_t :: struct {
tv_sec: c.long, tv_sec: c.long,
tv_nsec: c.long, tv_nsec: c.long,
} }
timeout: timespec_t err := internal_futex(f, FUTEX_WAIT_PRIVATE | FUTEX_WAIT, expected, &timespec_t{
timeout_ptr: ^timespec_t = nil tv_sec = (c.long)(duration/1e9),
tv_nsec = (c.long)(duration%1e9),
if duration > 0 { })
timeout.tv_sec = (c.long)(duration/1e9)
timeout.tv_nsec = (c.long)(duration%1e9)
timeout_ptr = &timeout
}
err := internal_futex(f, FUTEX_WAIT_PRIVATE | FUTEX_WAIT, expected, &timeout)
switch err { switch err {
case ESUCCESS, EINTR, EAGAIN, EINVAL: case ESUCCESS, EINTR, EAGAIN, EINVAL:
// okay // okay