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 › timeoutToWindowsInterval
timeoutToWindowsInterval
Threaded.timeoutToWindowsInterval
fn timeoutToWindowsInterval (timeout : Io .Timeout ) ?windows .LARGE_INTEGER
File
Code
fn timeoutToWindowsInterval (timeout : Io .Timeout ) ?windows .LARGE_INTEGER {
// * 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 ,
.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 ));
},
}
}