Zig 0.17.0-dev (Split by item)
This is an example of documentation generated by
ZigDoc , an alternative to Zig's built-in
Auto Doc feature. See also
examples in other modes/formats . The project being documented here (as the example) is the Zig library itself.
Zig › std/ › Io/ › Threaded.zig › sleepPosix
sleepPosix
Threaded.sleepPosix
fn sleepPosix (timeout : Io .Timeout ) Io .Cancelable !void
File
Code
fn sleepPosix (timeout : Io .Timeout ) Io .Cancelable !void {
const clock_id : posix .clockid_t = clockToPosix (switch (timeout ) {
.none => .awake ,
.duration => |d | d .clock ,
.deadline => |d | d .clock ,
});
const deadline_nanoseconds : i96 = switch (timeout ) {
.none => std .math .maxInt (i96 ),
.duration => |duration | duration .raw .nanoseconds ,
.deadline => |deadline | deadline .raw .nanoseconds ,
};
var timespec : posix .timespec = timestampToPosix (deadline_nanoseconds );
const syscall : Syscall = try .start ();
while (true ) {
const rc = posix .system .clock_nanosleep (clock_id , .{ .ABSTIME = switch (timeout ) {
.none , .duration => false ,
.deadline => true ,
} }, ×pec , ×pec );
switch (if (builtin .link_libc ) @as (posix .E , @fromBackingInt (@intCast (rc ))) else posix .errno (rc )) {
.INTR => {
try syscall .checkCancel ();
continue ;
},
// errors. The user had a chance to check clock resolution before
// getting here, which would have reported 0, making this a legal
// amount of time to sleep.
else => {
syscall .finish ();
return ;
},
}
}
}