mirror of
https://github.com/ziglang/zig.git
synced 2025-12-18 12:13:20 +00:00
ResetEvent: get abstime based on std.time
This commit is contained in:
parent
ca2d566ec8
commit
056b5a26c9
@ -333,12 +333,20 @@ const PosixEvent = struct {
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
var ts: os.timespec = undefined;
|
var ts: os.timespec = undefined;
|
||||||
var ts_ptr = &ts;
|
|
||||||
if (timeout) |timeout_ns| {
|
if (timeout) |timeout_ns| {
|
||||||
var tv: os.timeval = undefined;
|
var timeout_abs = timeout_ns;
|
||||||
assert(c.gettimeofday(&tv, null) == 0);
|
if (comptime std.Target.current.isDarwin()) {
|
||||||
ts.tv_sec = tv.tv_sec + @intCast(isize, timeout_ns / time.ns_per_s);
|
var tv: os.darwin.timeval = undefined;
|
||||||
ts.tv_nsec = (tv.tv_usec * time.microsecond) + @intCast(isize, timeout_ns % time.ns_per_s);
|
assert(os.darwin.gettimeofday(&tv, null) == 0);
|
||||||
|
timeout_abs += @intCast(u64, tv.tv_sec) * time.second;
|
||||||
|
timeout_abs += @intCast(u64, tv.tv_usec) * time.microsecond;
|
||||||
|
} else {
|
||||||
|
os.clock_gettime(os.CLOCK_REALTIME, &ts) catch unreachable;
|
||||||
|
timeout_abs += @intCast(u64, ts.tv_sec) * time.second;
|
||||||
|
timeout_abs += @intCast(u64, ts.tv_nsec);
|
||||||
|
}
|
||||||
|
ts.tv_sec = @intCast(@typeOf(ts.tv_sec), @divFloor(timeout_abs, time.second));
|
||||||
|
ts.tv_nsec = @intCast(@typeOf(ts.tv_nsec), @mod(timeout_abs, time.second));
|
||||||
}
|
}
|
||||||
|
|
||||||
var dummy_value: u32 = undefined;
|
var dummy_value: u32 = undefined;
|
||||||
@ -348,7 +356,7 @@ const PosixEvent = struct {
|
|||||||
while (self.state == wait_token) {
|
while (self.state == wait_token) {
|
||||||
const rc = switch (timeout == null) {
|
const rc = switch (timeout == null) {
|
||||||
true => c.pthread_cond_wait(&self.cond, &self.mutex),
|
true => c.pthread_cond_wait(&self.cond, &self.mutex),
|
||||||
else => c.pthread_cond_timedwait(&self.cond, &self.mutex, ts_ptr),
|
else => c.pthread_cond_timedwait(&self.cond, &self.mutex, &ts),
|
||||||
};
|
};
|
||||||
// TODO: rc appears to be the positive error code making os.errno() always return 0 on linux
|
// TODO: rc appears to be the positive error code making os.errno() always return 0 on linux
|
||||||
switch (std.math.max(@as(c_int, os.errno(rc)), rc)) {
|
switch (std.math.max(@as(c_int, os.errno(rc)), rc)) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user