diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-05-04 15:19:14 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-05-04 15:19:14 -0400 |
| commit | 6a34da963b4712da7fa20079e6ab557455ffe4bf (patch) | |
| tree | deda8f8f46e2033b1f6c3d19d8e2b52ae1fab9e6 /std/os | |
| parent | 6f0aa801c80a434b7cc931e879d234a8de501e38 (diff) | |
| parent | 09cbcf8841a0b80cdbdf40c2b48acccbaa945ce8 (diff) | |
| download | zig-6a34da963b4712da7fa20079e6ab557455ffe4bf.tar.gz zig-6a34da963b4712da7fa20079e6ab557455ffe4bf.zip | |
Merge branch 'LemonBoy-stdlib-32b'
Diffstat (limited to 'std/os')
| -rw-r--r-- | std/os/linux.zig | 4 | ||||
| -rw-r--r-- | std/os/time.zig | 17 |
2 files changed, 12 insertions, 9 deletions
diff --git a/std/os/linux.zig b/std/os/linux.zig index 425df3a55d..8471a1861b 100644 --- a/std/os/linux.zig +++ b/std/os/linux.zig @@ -1101,8 +1101,8 @@ pub fn sigaction(sig: u6, noalias act: *const Sigaction, noalias oact: ?*Sigacti const NSIG = 65; const sigset_t = [128 / @sizeOf(usize)]usize; -const all_mask = []usize{maxInt(usize)}; -const app_mask = []usize{0xfffffffc7fffffff}; +const all_mask = []u32{0xffffffff, 0xffffffff}; +const app_mask = []u32{0xfffffffc, 0x7fffffff}; const k_sigaction = extern struct { handler: extern fn (i32) void, diff --git a/std/os/time.zig b/std/os/time.zig index d742c5d03b..abb6412843 100644 --- a/std/os/time.zig +++ b/std/os/time.zig @@ -3,6 +3,7 @@ const builtin = @import("builtin"); const Os = builtin.Os; const debug = std.debug; const testing = std.testing; +const math = std.math; const windows = std.os.windows; const linux = std.os.linux; @@ -12,33 +13,34 @@ const posix = std.os.posix; pub const epoch = @import("epoch.zig"); -/// Sleep for the specified duration +/// Spurious wakeups are possible and no precision of timing is guaranteed. pub fn sleep(nanoseconds: u64) void { switch (builtin.os) { Os.linux, Os.macosx, Os.ios, Os.freebsd, Os.netbsd => { const s = nanoseconds / ns_per_s; const ns = nanoseconds % ns_per_s; - posixSleep(@intCast(u63, s), @intCast(u63, ns)); + posixSleep(s, ns); }, Os.windows => { const ns_per_ms = ns_per_s / ms_per_s; const milliseconds = nanoseconds / ns_per_ms; - windows.Sleep(@intCast(windows.DWORD, milliseconds)); + const ms_that_will_fit = std.math.cast(windows.DWORD, milliseconds) catch std.math.maxInt(windows.DWORD); + windows.Sleep(ms_that_will_fit); }, else => @compileError("Unsupported OS"), } } -pub fn posixSleep(seconds: u63, nanoseconds: u63) void { +/// Spurious wakeups are possible and no precision of timing is guaranteed. +pub fn posixSleep(seconds: u64, nanoseconds: u64) void { var req = posix.timespec{ - .tv_sec = seconds, - .tv_nsec = nanoseconds, + .tv_sec = std.math.cast(isize, seconds) catch std.math.maxInt(isize), + .tv_nsec = std.math.cast(isize, nanoseconds) catch std.math.maxInt(isize), }; var rem: posix.timespec = undefined; while (true) { const ret_val = posix.nanosleep(&req, &rem); const err = posix.getErrno(ret_val); - if (err == 0) return; switch (err) { posix.EFAULT => unreachable, posix.EINVAL => { @@ -50,6 +52,7 @@ pub fn posixSleep(seconds: u63, nanoseconds: u63) void { req = rem; continue; }, + // This prong handles success as well as unexpected errors. else => return, } } |
