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 › timeoutToWindowsInterval Private Function timeoutToWindowsInterval Doc Source Private Function std.Io.Threaded.timeoutToWindowsInterval
fn timeoutToWindowsInterval (timeout : Io .Timeout ) ?windows .LARGE_INTEGER Params File Io/Threaded.zig: 18003
18003
18004
18005
18006
18007
18008
18009
18010
18011
18012
18013
18014
18015
18016
18017
18018
18019
18020
18021
18022
18023
18024
18025
18026
18027
18028
18029
18030
18031
18032 fn timeoutToWindowsInterval (timeout : Io .Timeout ) ?windows .LARGE_INTEGER {
// ntdll only supports two combinations:
// * real-time (`.real`) sleeps with absolute deadlines
// * monotonic (`.awake`/`.boot`) sleeps with relative durations
const clock = switch (timeout ) {
.none => return null ,
.duration => |d | d .clock ,
.deadline => |d | d .clock ,
};
switch (clock ) {
.cpu_process , .cpu_thread => unreachable , // cannot sleep for CPU time
.real => {
const deadline = switch (timeout ) {
.none => unreachable ,
.duration => |d | nowWindows (clock ).addDuration (d .raw ),
.deadline => |d | d .raw ,
};
const epoch_ns = std .time .epoch .windows * std .time .ns_per_s ;
return @intCast (@max (@divTrunc (deadline .nanoseconds - epoch_ns , 100 ), 0 ));
},
.awake , .boot => {
const duration = switch (timeout ) {
.none => unreachable ,
.duration => |d | d .raw ,
.deadline => |d | nowWindows (clock ).durationTo (d .raw ),
};
return @intCast (@min (@divTrunc (-duration .nanoseconds , 100 ), -1 ));
},
}
}