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. Public Function
Blocks the calling thread until either the logical boolean is set, the timeout expires, or a spurious wakeup occurs. If the timeout expires or a spurious wakeup occurs, error.Timeout is returned.
pubfnwaitTimeout(event: *Event, io: Io, timeout: Timeout) WaitTimeoutError!void {
if (@cmpxchgStrong(Event, event, .unset, .waiting, .acquire, .acquire)) |prev| switch (prev) {
.unset => unreachable,
.waiting => {},
.is_set => return,
};
errdefer {
// Ideally we would restore the event back to `.unset` instead of `.waiting`, but there// might be other threads waiting on the event. In theory we could track the *number* of// waiting threads in the unused bits of the `Event`, but that has its own problem: the// waiters would wake up when a *new waiter* was added. So it's easiest to just leave// the state at `.waiting`---at worst it causes one redundant call to `futexWake`.
}
tryio.futexWaitTimeout(Event, event, .waiting, timeout);
switch (@atomicLoad(Event, event, .acquire)) {
.unset => unreachable, // `reset` called before pending `wait` returned
.waiting => returnerror.Timeout,
.is_set => return,
}
}
Blocks the calling thread until either the logical boolean is set, the timeout expires, or a spurious wakeup occurs. If the timeout expires or a spurious wakeup occurs,
error.Timeoutis returned.