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
pubfnwaitUncancelable(cond: *Condition, io: Io, mutex: *Mutex) void {
varepoch = cond.epoch.load(.acquire); // `.acquire` to ensure ordered before state load
{
constprev_state = cond.state.fetchAdd(.{ .waiters = 1, .signals = 0 }, .monotonic);
assert(prev_state.waiters < math.maxInt(u16)); // overflow caused by too many waiters
}
mutex.unlock(io);
defermutex.lockUncancelable(io);
while (true) {
io.futexWaitUncancelable(u32, &cond.epoch.raw, epoch);
epoch = cond.epoch.load(.acquire); // `.acquire` to ensure ordered before `state` laod// Even on error, try to consume a pending signal first. Otherwise a race might// cause a signal to get stuck in the state with no corresponding waiter.
{
varprev_state = cond.state.load(.monotonic);
while (prev_state.signals > 0) {
prev_state = cond.state.cmpxchgWeak(prev_state, .{
.waiters = prev_state.waiters - 1,
.signals = prev_state.signals - 1,
}, .acquire, .monotonic) orelse {
// We successfully consumed a signal.return;
};
}
}
// There are no more signals available; this was a spurious wakeup,// so we'll loop back to the futex wait.
}
}
Same as
wait, except does not introduce a cancelation point.See
Future.cancelfor a description of cancelation points.