Function nanosleep [src]
Spurious wakeups are possible and no precision of timing is guaranteed.
Prototype
pub fn nanosleep(seconds: u64, nanoseconds: u64) void
Parameters
seconds: u64
nanoseconds: u64
Source
pub fn nanosleep(seconds: u64, nanoseconds: u64) void {
var req = timespec{
.sec = cast(isize, seconds) orelse maxInt(isize),
.nsec = cast(isize, nanoseconds) orelse maxInt(isize),
};
var rem: timespec = undefined;
while (true) {
switch (errno(system.nanosleep(&req, &rem))) {
.FAULT => unreachable,
.INVAL => {
// Sometimes Darwin returns EINVAL for no reason.
// We treat it as a spurious wakeup.
return;
},
.INTR => {
req = rem;
continue;
},
// This prong handles success as well as unexpected errors.
else => return,
}
}
}