| ... | ... | @@ -333,12 +333,20 @@ const PosixEvent = struct { |
| 333 | 333 | return false; |
| 334 | 334 | |
| 335 | 335 | var ts: os.timespec = undefined; |
| 336 | | var ts_ptr = &ts; |
| 337 | 336 | if (timeout) |timeout_ns| { |
| 338 | | var tv: os.timeval = undefined; |
| 339 | | assert(c.gettimeofday(&tv, null) == 0); |
| 340 | | ts.tv_sec = tv.tv_sec + @intCast(isize, timeout_ns / time.ns_per_s); |
| 341 | | ts.tv_nsec = (tv.tv_usec * time.microsecond) + @intCast(isize, timeout_ns % time.ns_per_s); |
| 337 | var timeout_abs = timeout_ns; |
| 338 | if (comptime std.Target.current.isDarwin()) { |
| 339 | var tv: os.darwin.timeval = undefined; |
| 340 | assert(os.darwin.gettimeofday(&tv, null) == 0); |
| 341 | timeout_abs += @intCast(u64, tv.tv_sec) * time.second; |
| 342 | timeout_abs += @intCast(u64, tv.tv_usec) * time.microsecond; |
| 343 | } else { |
| 344 | os.clock_gettime(os.CLOCK_REALTIME, &ts) catch unreachable; |
| 345 | timeout_abs += @intCast(u64, ts.tv_sec) * time.second; |
| 346 | timeout_abs += @intCast(u64, ts.tv_nsec); |
| 347 | } |
| 348 | ts.tv_sec = @intCast(@typeOf(ts.tv_sec), @divFloor(timeout_abs, time.second)); |
| 349 | ts.tv_nsec = @intCast(@typeOf(ts.tv_nsec), @mod(timeout_abs, time.second)); |
| 342 | 350 | } |
| 343 | 351 | |
| 344 | 352 | var dummy_value: u32 = undefined; |
| ... | ... | @@ -348,7 +356,7 @@ const PosixEvent = struct { |
| 348 | 356 | while (self.state == wait_token) { |
| 349 | 357 | const rc = switch (timeout == null) { |
| 350 | 358 | true => c.pthread_cond_wait(&self.cond, &self.mutex), |
| 351 | | else => c.pthread_cond_timedwait(&self.cond, &self.mutex, ts_ptr), |
| 359 | else => c.pthread_cond_timedwait(&self.cond, &self.mutex, &ts), |
| 352 | 360 | }; |
| 353 | 361 | // TODO: rc appears to be the positive error code making os.errno() always return 0 on linux |
| 354 | 362 | switch (std.math.max(@as(c_int, os.errno(rc)), rc)) { |