| author | |
| committer | |
| log | 751ab72a82a0edc4c5c129c6675a33d3cd57fa73 |
| tree | 54ddc2a4c43b83e85293d8795fe6b21b10e889c9 |
| parent | 86eb1836682cecea199748842767cf2d9cc2ea62 |
5 files changed, 35 insertions(+), 4 deletions(-)
std/c/index.zig+1| ... | @@ -40,3 +40,4 @@ pub extern "c" fn readlink(noalias path: &const u8, noalias buf: &u8, bufsize: u | ... | @@ -40,3 +40,4 @@ pub extern "c" fn readlink(noalias path: &const u8, noalias buf: &u8, bufsize: u |
| 40 | pub extern "c" fn realpath(noalias file_name: &const u8, noalias resolved_name: &u8) -> ?&u8; | 40 | pub extern "c" fn realpath(noalias file_name: &const u8, noalias resolved_name: &u8) -> ?&u8; |
| 41 | pub extern "c" fn sigprocmask(how: c_int, noalias set: &const sigset_t, noalias oset: ?&sigset_t) -> c_int; | 41 | pub extern "c" fn sigprocmask(how: c_int, noalias set: &const sigset_t, noalias oset: ?&sigset_t) -> c_int; |
| 42 | pub extern "c" fn sigaction(sig: c_int, noalias act: &const Sigaction, noalias oact: ?&Sigaction) -> c_int; | 42 | pub extern "c" fn sigaction(sig: c_int, noalias act: &const Sigaction, noalias oact: ?&Sigaction) -> c_int; |
| 43 | pub extern "c" fn nanosleep(rqtp: &const timespec, rmtp: ?&timespec) -> c_int; |
std/os/darwin.zig+6| ... | @@ -221,6 +221,10 @@ pub fn readlink(noalias path: &const u8, noalias buf_ptr: &u8, buf_len: usize) - | ... | @@ -221,6 +221,10 @@ pub fn readlink(noalias path: &const u8, noalias buf_ptr: &u8, buf_len: usize) - |
| 221 | errnoWrap(c.readlink(path, buf_ptr, buf_len)) | 221 | errnoWrap(c.readlink(path, buf_ptr, buf_len)) |
| 222 | } | 222 | } |
| 223 | 223 | ||
| 224 | pub fn nanosleep(req: &const timespec, rem: ?&timespec) -> usize { | ||
| 225 | errnoWrap(c.nanosleep(req, rem)) | ||
| 226 | } | ||
| 227 | |||
| 224 | pub fn realpath(noalias filename: &const u8, noalias resolved_name: &u8) -> usize { | 228 | pub fn realpath(noalias filename: &const u8, noalias resolved_name: &u8) -> usize { |
| 225 | if (c.realpath(filename, resolved_name) == null) @bitCast(usize, -isize(*c._errno())) else 0 | 229 | if (c.realpath(filename, resolved_name) == null) @bitCast(usize, -isize(*c._errno())) else 0 |
| 226 | } | 230 | } |
| ... | @@ -255,6 +259,8 @@ pub fn sigaction(sig: u5, noalias act: &const Sigaction, noalias oact: ?&Sigacti | ... | @@ -255,6 +259,8 @@ pub fn sigaction(sig: u5, noalias act: &const Sigaction, noalias oact: ?&Sigacti |
| 255 | pub const sigset_t = c.sigset_t; | 259 | pub const sigset_t = c.sigset_t; |
| 256 | pub const empty_sigset = sigset_t(0); | 260 | pub const empty_sigset = sigset_t(0); |
| 257 | 261 | ||
| 262 | pub const timespec = c.timespec; | ||
| 263 | |||
| 258 | /// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. | 264 | /// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. |
| 259 | pub const Sigaction = struct { | 265 | pub const Sigaction = struct { |
| 260 | handler: extern fn(i32), | 266 | handler: extern fn(i32), |
std/os/index.zig+24-2| ... | @@ -949,7 +949,21 @@ pub fn readLink(allocator: &Allocator, pathname: []const u8) -> %[]u8 { | ... | @@ -949,7 +949,21 @@ pub fn readLink(allocator: &Allocator, pathname: []const u8) -> %[]u8 { |
| 949 | } | 949 | } |
| 950 | } | 950 | } |
| 951 | 951 | ||
| 952 | pub fn sleep(seconds: u64, nanoseconds: u64) { | 952 | pub fn sleep(seconds: usize, nanoseconds: usize) { |
| 953 | switch(builtin.os) { | ||
| 954 | Os.linux, Os.darwin, Os.macosx, Os.ios => { | ||
| 955 | posixSleep(u63(seconds), u63(nanoseconds)); | ||
| 956 | }, | ||
| 957 | Os.windows => { | ||
| 958 | const milliseconds = seconds * 1000 + nanoseconds / 1000000; | ||
| 959 | windows.Sleep(windows.DWORD(milliseconds)); | ||
| 960 | }, | ||
| 961 | else => @compileError("Unsupported OS"), | ||
| 962 | } | ||
| 963 | } | ||
| 964 | |||
| 965 | const u63 = @IntType(false, 63); | ||
| 966 | pub fn posixSleep(seconds: u63, nanoseconds: u63) { | ||
| 953 | var req = posix.timespec { | 967 | var req = posix.timespec { |
| 954 | .tv_sec = seconds, | 968 | .tv_sec = seconds, |
| 955 | .tv_nsec = nanoseconds, | 969 | .tv_nsec = nanoseconds, |
| ... | @@ -961,7 +975,11 @@ pub fn sleep(seconds: u64, nanoseconds: u64) { | ... | @@ -961,7 +975,11 @@ pub fn sleep(seconds: u64, nanoseconds: u64) { |
| 961 | if (err == 0) return; | 975 | if (err == 0) return; |
| 962 | switch (err) { | 976 | switch (err) { |
| 963 | posix.EFAULT => unreachable, | 977 | posix.EFAULT => unreachable, |
| 964 | posix.EINVAL => unreachable, | 978 | posix.EINVAL => { |
| 979 | // Sometimes Darwin returns EINVAL for no reason. | ||
| 980 | // We treat it as a spurious wakeup. | ||
| 981 | return; | ||
| 982 | }, | ||
| 965 | posix.EINTR => { | 983 | posix.EINTR => { |
| 966 | req = rem; | 984 | req = rem; |
| 967 | continue; | 985 | continue; |
| ... | @@ -970,3 +988,7 @@ pub fn sleep(seconds: u64, nanoseconds: u64) { | ... | @@ -970,3 +988,7 @@ pub fn sleep(seconds: u64, nanoseconds: u64) { |
| 970 | } | 988 | } |
| 971 | } | 989 | } |
| 972 | } | 990 | } |
| 991 | |||
| 992 | test "os.sleep" { | ||
| 993 | sleep(0, 1); | ||
| 994 | } |
std/os/linux_x86_64.zig+2-2| ... | @@ -484,6 +484,6 @@ pub const Stat = extern struct { | ... | @@ -484,6 +484,6 @@ pub const Stat = extern struct { |
| 484 | }; | 484 | }; |
| 485 | 485 | ||
| 486 | pub const timespec = extern struct { | 486 | pub const timespec = extern struct { |
| 487 | tv_sec: usize, | 487 | tv_sec: isize, |
| 488 | tv_nsec: usize, | 488 | tv_nsec: isize, |
| 489 | }; | 489 | }; |
std/os/windows/index.zig+2| ... | @@ -37,6 +37,8 @@ pub extern "kernel32" stdcallcc fn WriteFile(in_hFile: HANDLE, in_lpBuffer: &con | ... | @@ -37,6 +37,8 @@ pub extern "kernel32" stdcallcc fn WriteFile(in_hFile: HANDLE, in_lpBuffer: &con |
| 37 | in_nNumberOfBytesToWrite: DWORD, out_lpNumberOfBytesWritten: ?&DWORD, | 37 | in_nNumberOfBytesToWrite: DWORD, out_lpNumberOfBytesWritten: ?&DWORD, |
| 38 | in_out_lpOverlapped: ?&OVERLAPPED) -> BOOL; | 38 | in_out_lpOverlapped: ?&OVERLAPPED) -> BOOL; |
| 39 | 39 | ||
| 40 | pub extern "kernel32" stdcallcc fn Sleep(dwMilliseconds: DWORD); | ||
| 41 | |||
| 40 | pub const PROV_RSA_FULL = 1; | 42 | pub const PROV_RSA_FULL = 1; |
| 41 | 43 | ||
| 42 | pub const UNICODE = false; | 44 | pub const UNICODE = false; |