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. Private Function
The thread is neither in a syscall nor entering one, but we want to check for cancelation anyway. If there is a pending cancel request, acknowledge it and return error.Canceled.
fncheckCancel() Io.Cancelable!void {
constthread = Thread.currentorelsereturn;
switch (thread.cancel_protection) {
.blocked => return,
.unblocked => {},
}
// Here, unlike `Syscall.checkCancel`, it's not particularly likely that we're canceled, so// it seems preferable to do a cheap atomic load and, in the unlikely case, a separate store// to acknowledge. Besides, the state transitions we need here can't be done with one atomic// OR/AND/XOR on `Status.cancelation`, so we don't actually have any other option.conststatus = thread.status.load(.monotonic);
switch (status.cancelation) {
.parked => unreachable,
.blocked => unreachable,
.blocked_alertable => unreachable,
.blocked_alertable_canceling => unreachable,
.blocked_canceling => unreachable,
.none, .canceled => {},
.canceling => {
thread.status.store(.{
.cancelation = .canceled,
.awaitable = status.awaitable,
}, .monotonic);
returnerror.Canceled;
},
}
}
The thread is neither in a syscall nor entering one, but we want to check for cancelation anyway. If there is a pending cancel request, acknowledge it and return
error.Canceled.