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
pubfnlock(rl: *RwLock, io: Io) Io.Cancelable!void {
_ = @atomicRmw(usize, &rl.state, .Add, writer, .seq_cst);
rl.mutex.lock(io) catch |err| switch (err) {
error.Canceled => {
_ = @atomicRmw(usize, &rl.state, .Sub, writer, .seq_cst);
returnerror.Canceled;
},
};
conststate = @atomicRmw(usize, &rl.state, .Add, is_writing -% writer, .seq_cst);
if (state & reader_mask != 0)
rl.semaphore.wait(io) catch |err| switch (err) {
error.Canceled => {
// Clearing `is_writing` while still holding the mutex means the last reader// either saw it set, and posts a permit only we can consume, or did not and// never posts. A stale permit would let the next writer in past the readers.constprev_state = @atomicRmw(usize, &rl.state, .And, ~is_writing, .seq_cst);
if (prev_state & reader_mask == 0) rl.semaphore.waitUncancelable(io);
rl.mutex.unlock(io);
returnerror.Canceled;
},
};
}