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.

tryLock

RwLock.tryLock
pub fn tryLock(rl: *RwLock, io: Io) bool

File

lib/std/Io/RwLock.zig:28

Code

pub fn tryLock(rl: *RwLock, io: Io) bool {
    if (rl.mutex.tryLock()) {
        const state = @atomicLoad(usize, &rl.state, .seq_cst);
        if (state & reader_mask == 0) {
            _ = @atomicRmw(usize, &rl.state, .Or, is_writing, .seq_cst);
            return true;
        }

        rl.mutex.unlock(io);
    }

    return false;
}