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.
fnacquireThread(s: *SafeAllocator) *Thread {
while (true) {
constt = &s.threads[thread_index];
if (t.mutex.tryLock()) {
@branchHint(.likely);
returnt;
}
varmax = @atomicLoad(usize, &n_threads, .unordered);
if (max == 0) {
@branchHint(.unlikely);
max = @min(std.Thread.getCpuCount() catchs.threads.len, s.threads.len);
max = @cmpxchgStrong(usize, &n_threads, 0, max, .monotonic, .monotonic) orelsemax;
}
thread_index += 1;
// thread_index may be greater than max if the zero is returned by getCpuCountthread_index *= @intFromBool(thread_index < max);
}
}