aboutsummaryrefslogtreecommitdiffstats
path: root/executor/common_linux.h
diff options
context:
space:
mode:
Diffstat (limited to 'executor/common_linux.h')
-rw-r--r--executor/common_linux.h24
1 files changed, 9 insertions, 15 deletions
diff --git a/executor/common_linux.h b/executor/common_linux.h
index 5f3eec25f..ad653f396 100644
--- a/executor/common_linux.h
+++ b/executor/common_linux.h
@@ -51,26 +51,20 @@ static int event_isset(event_t* ev)
return __atomic_load_n(&ev->state, __ATOMIC_ACQUIRE);
}
-static int event_timedwait(event_t* ev, uint64 timeout_ms)
+static int event_timedwait(event_t* ev, uint64 timeout)
{
- struct timespec ts;
- if (clock_gettime(CLOCK_MONOTONIC, &ts))
- fail("clock_gettime failed");
- const uint64 kNsPerSec = 1000 * 1000 * 1000;
- uint64 start_ns = (uint64)ts.tv_sec * kNsPerSec + (uint64)ts.tv_nsec;
- uint64 now_ns = start_ns;
- uint64 timeout_ns = timeout_ms * 1000 * 1000;
+ uint64 start = current_time_ms();
+ uint64 now = start;
for (;;) {
- uint64 remain_ns = timeout_ns - (now_ns - start_ns);
- ts.tv_sec = remain_ns / kNsPerSec;
- ts.tv_nsec = remain_ns % kNsPerSec;
+ uint64 remain = timeout - (now - start);
+ struct timespec ts;
+ ts.tv_sec = remain / 1000;
+ ts.tv_nsec = (remain % 1000) * 1000 * 1000;
syscall(SYS_futex, &ev->state, FUTEX_WAIT, 0, &ts);
if (__atomic_load_n(&ev->state, __ATOMIC_RELAXED))
return 1;
- if (clock_gettime(CLOCK_MONOTONIC, &ts))
- fail("clock_gettime failed");
- now_ns = (uint64)ts.tv_sec * kNsPerSec + (uint64)ts.tv_nsec;
- if (now_ns - start_ns > timeout_ns)
+ now = current_time_ms();
+ if (now - start > timeout)
return 0;
}
}