aboutsummaryrefslogtreecommitdiff
path: root/std
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2017-09-06 16:59:22 -0400
committerAndrew Kelley <superjoe30@gmail.com>2017-09-06 16:59:22 -0400
commit7e59f4ff69f9a8634c4e8d49cea95a3b55dbe771 (patch)
tree36535ecb427b8ef23e884965703a7198bd7cd797 /std
parent1f2548ec5f19bf2e7ab66b0349f4953499897b10 (diff)
downloadzig-7e59f4ff69f9a8634c4e8d49cea95a3b55dbe771.tar.gz
zig-7e59f4ff69f9a8634c4e8d49cea95a3b55dbe771.zip
std: add os.sleep
Diffstat (limited to 'std')
-rw-r--r--std/os/index.zig22
-rw-r--r--std/os/linux.zig4
-rw-r--r--std/os/linux_x86_64.zig4
3 files changed, 28 insertions, 2 deletions
diff --git a/std/os/index.zig b/std/os/index.zig
index 4314f6f291..2912be2cc8 100644
--- a/std/os/index.zig
+++ b/std/os/index.zig
@@ -924,3 +924,25 @@ pub fn readLink(allocator: &Allocator, pathname: []const u8) -> %[]u8 {
return result_buf[0..ret_val];
}
}
+
+pub fn sleep(seconds: u64, nanoseconds: u64) {
+ var req = posix.timespec {
+ .tv_sec = seconds,
+ .tv_nsec = nanoseconds,
+ };
+ 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 => unreachable,
+ posix.EINTR => {
+ req = rem;
+ continue;
+ },
+ else => return,
+ }
+ }
+}
diff --git a/std/os/linux.zig b/std/os/linux.zig
index 903548ef09..d57e966ab5 100644
--- a/std/os/linux.zig
+++ b/std/os/linux.zig
@@ -459,6 +459,10 @@ pub fn waitpid(pid: i32, status: &i32, options: i32) -> usize {
arch.syscall4(arch.SYS_wait4, usize(pid), @ptrToInt(status), @bitCast(usize, isize(options)), 0)
}
+pub fn nanosleep(req: &const timespec, rem: ?&timespec) -> usize {
+ arch.syscall2(arch.SYS_nanosleep, @ptrToInt(req), @ptrToInt(rem))
+}
+
const NSIG = 65;
const sigset_t = [128]u8;
const all_mask = []u8 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, };
diff --git a/std/os/linux_x86_64.zig b/std/os/linux_x86_64.zig
index 658019da30..ad418d173b 100644
--- a/std/os/linux_x86_64.zig
+++ b/std/os/linux_x86_64.zig
@@ -476,6 +476,6 @@ pub const Stat = extern struct {
};
pub const timespec = extern struct {
- tv_sec: isize,
- tv_nsec: isize,
+ tv_sec: usize,
+ tv_nsec: usize,
};