| author | |
| committer | |
| log | f1610f6c1ddbb5c2b42d2ecac433b8eff11d5a3a |
| tree | 4fb8fd925fabb7fd7d97f7e0e09e40ad998a9a1d |
| parent | abf959a0c90418c383cc4f10242dbcc2a2e974fd |
| signature |
2 files changed, 8 insertions(+), 13 deletions(-)
std/os.zig-13| ... | @@ -2315,19 +2315,6 @@ pub fn realpathW(pathname: [*]const u16, out_buffer: *[MAX_PATH_BYTES]u8) RealPa | ... | @@ -2315,19 +2315,6 @@ pub fn realpathW(pathname: [*]const u16, out_buffer: *[MAX_PATH_BYTES]u8) RealPa |
| 2315 | 2315 | ||
| 2316 | /// Spurious wakeups are possible and no precision of timing is guaranteed. | 2316 | /// Spurious wakeups are possible and no precision of timing is guaranteed. |
| 2317 | pub fn nanosleep(seconds: u64, nanoseconds: u64) void { | 2317 | pub fn nanosleep(seconds: u64, nanoseconds: u64) void { |
| 2318 | if (windows.is_the_target and !builtin.link_libc) { | ||
| 2319 | // TODO https://github.com/ziglang/zig/issues/1284 | ||
| 2320 | const small_s = math.cast(windows.DWORD, seconds) catch math.maxInt(windows.DWORD); | ||
| 2321 | const ms_from_s = math.mul(windows.DWORD, small_s, std.time.ms_per_s) catch math.maxInt(windows.DWORD); | ||
| 2322 | |||
| 2323 | const ns_per_ms = std.time.ns_per_s / std.time.ms_per_s; | ||
| 2324 | const big_ms_from_ns = nanoseconds / ns_per_ms; | ||
| 2325 | const ms_from_ns = math.cast(windows.DWORD, big_ms_from_ns) catch math.maxInt(windows.DWORD); | ||
| 2326 | |||
| 2327 | const ms = math.add(windows.DWORD, ms_from_s, ms_from_ns) catch math.maxInt(windows.DWORD); | ||
| 2328 | windows.kernel32.Sleep(ms); | ||
| 2329 | return; | ||
| 2330 | } | ||
| 2331 | var req = timespec{ | 2318 | var req = timespec{ |
| 2332 | .tv_sec = math.cast(isize, seconds) catch math.maxInt(isize), | 2319 | .tv_sec = math.cast(isize, seconds) catch math.maxInt(isize), |
| 2333 | .tv_nsec = math.cast(isize, nanoseconds) catch math.maxInt(isize), | 2320 | .tv_nsec = math.cast(isize, nanoseconds) catch math.maxInt(isize), |
std/time.zig+8| ... | @@ -3,11 +3,19 @@ const std = @import("std.zig"); | ... | @@ -3,11 +3,19 @@ const std = @import("std.zig"); |
| 3 | const assert = std.debug.assert; | 3 | const assert = std.debug.assert; |
| 4 | const testing = std.testing; | 4 | const testing = std.testing; |
| 5 | const os = std.os; | 5 | const os = std.os; |
| 6 | const math = std.math; | ||
| 6 | 7 | ||
| 7 | pub const epoch = @import("time/epoch.zig"); | 8 | pub const epoch = @import("time/epoch.zig"); |
| 8 | 9 | ||
| 9 | /// Spurious wakeups are possible and no precision of timing is guaranteed. | 10 | /// Spurious wakeups are possible and no precision of timing is guaranteed. |
| 10 | pub fn sleep(nanoseconds: u64) void { | 11 | pub fn sleep(nanoseconds: u64) void { |
| 12 | if (os.windows.is_the_target) { | ||
| 13 | const ns_per_ms = ns_per_s / ms_per_s; | ||
| 14 | const big_ms_from_ns = nanoseconds / ns_per_ms; | ||
| 15 | const ms = math.cast(os.windows.DWORD, big_ms_from_ns) catch math.maxInt(os.windows.DWORD); | ||
| 16 | os.windows.kernel32.Sleep(ms); | ||
| 17 | return; | ||
| 18 | } | ||
| 11 | const s = nanoseconds / ns_per_s; | 19 | const s = nanoseconds / ns_per_s; |
| 12 | const ns = nanoseconds % ns_per_s; | 20 | const ns = nanoseconds % ns_per_s; |
| 13 | std.os.nanosleep(s, ns); | 21 | std.os.nanosleep(s, ns); |