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 standard library.
std › Io › Threaded › sleepPosix Private Function sleepPosix Doc Source Private Function std.Io.Threaded.sleepPosix
fn sleepPosix (timeout : Io .Timeout ) Io .Cancelable !void Params File Io/Threaded.zig: 11863
11863
11864
11865
11866
11867
11868
11869
11870
11871
11872
11873
11874
11875
11876
11877
11878
11879
11880
11881
11882
11883
11884
11885
11886
11887
11888
11889
11890
11891
11892
11893
11894
11895
11896
11897 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 );
// POSIX-standard libc clock_nanosleep() returns *positive* errno values directly
switch (if (builtin .link_libc ) @as (posix .E , @fromBackingInt (@intCast (rc ))) else posix .errno (rc )) {
.INTR => {
try syscall .checkCancel ();
continue ;
},
// Handles SUCCESS as well as clock not available and unexpected
// 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 ;
},
}
}
}