| author | |
| committer | |
| log | 7e59f4ff69f9a8634c4e8d49cea95a3b55dbe771 |
| tree | 36535ecb427b8ef23e884965703a7198bd7cd797 |
| parent | 1f2548ec5f19bf2e7ab66b0349f4953499897b10 |
3 files changed, 28 insertions(+), 2 deletions(-)
std/os/index.zig+22| ... | @@ -924,3 +924,25 @@ pub fn readLink(allocator: &Allocator, pathname: []const u8) -> %[]u8 { | ... | @@ -924,3 +924,25 @@ pub fn readLink(allocator: &Allocator, pathname: []const u8) -> %[]u8 { |
| 924 | return result_buf[0..ret_val]; | 924 | return result_buf[0..ret_val]; |
| 925 | } | 925 | } |
| 926 | } | 926 | } |
| 927 | |||
| 928 | pub fn sleep(seconds: u64, nanoseconds: u64) { | ||
| 929 | var req = posix.timespec { | ||
| 930 | .tv_sec = seconds, | ||
| 931 | .tv_nsec = nanoseconds, | ||
| 932 | }; | ||
| 933 | var rem: posix.timespec = undefined; | ||
| 934 | while (true) { | ||
| 935 | const ret_val = posix.nanosleep(&req, &rem); | ||
| 936 | const err = posix.getErrno(ret_val); | ||
| 937 | if (err == 0) return; | ||
| 938 | switch (err) { | ||
| 939 | posix.EFAULT => unreachable, | ||
| 940 | posix.EINVAL => unreachable, | ||
| 941 | posix.EINTR => { | ||
| 942 | req = rem; | ||
| 943 | continue; | ||
| 944 | }, | ||
| 945 | else => return, | ||
| 946 | } | ||
| 947 | } | ||
| 948 | } |
std/os/linux.zig+4| ... | @@ -459,6 +459,10 @@ pub fn waitpid(pid: i32, status: &i32, options: i32) -> usize { | ... | @@ -459,6 +459,10 @@ pub fn waitpid(pid: i32, status: &i32, options: i32) -> usize { |
| 459 | arch.syscall4(arch.SYS_wait4, usize(pid), @ptrToInt(status), @bitCast(usize, isize(options)), 0) | 459 | arch.syscall4(arch.SYS_wait4, usize(pid), @ptrToInt(status), @bitCast(usize, isize(options)), 0) |
| 460 | } | 460 | } |
| 461 | 461 | ||
| 462 | pub fn nanosleep(req: &const timespec, rem: ?&timespec) -> usize { | ||
| 463 | arch.syscall2(arch.SYS_nanosleep, @ptrToInt(req), @ptrToInt(rem)) | ||
| 464 | } | ||
| 465 | |||
| 462 | const NSIG = 65; | 466 | const NSIG = 65; |
| 463 | const sigset_t = [128]u8; | 467 | const sigset_t = [128]u8; |
| 464 | const all_mask = []u8 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, }; | 468 | const all_mask = []u8 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, }; |
std/os/linux_x86_64.zig+2-2| ... | @@ -476,6 +476,6 @@ pub const Stat = extern struct { | ... | @@ -476,6 +476,6 @@ pub const Stat = extern struct { |
| 476 | }; | 476 | }; |
| 477 | 477 | ||
| 478 | pub const timespec = extern struct { | 478 | pub const timespec = extern struct { |
| 479 | tv_sec: isize, | 479 | tv_sec: usize, |
| 480 | tv_nsec: isize, | 480 | tv_nsec: usize, |
| 481 | }; | 481 | }; |