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.
constThread = struct {
/// Avoid false sharing._: voidalign(std.atomic.cache_line) = {},
/// Protects the state in this struct (per-thread state).////// Threads lock this before accessing their own state in order/// to support freelist reclamation.mutex: std.atomic.Mutex = .unlocked,
/// For each size class, tracks the next address to be returned from/// `alloc` when the freelist is empty.next_addrs: [size_class_count]usize = @splat(0),
/// For each size class, points to the freed pointer.frees: [size_class_count]usize = @splat(0),
fnlock() *Thread {
varindex = thread_index;
{
constt = &global.threads[index];
if (t.mutex.tryLock()) {
@branchHint(.likely);
returnt;
}
}
constcpu_count = getCpuCount();
assert(cpu_count != 0);
while (true) {
index = (index + 1) % cpu_count;
constt = &global.threads[index];
if (t.mutex.tryLock()) {
thread_index = index;
returnt;
}
}
}
fnunlock(t: *Thread) void {
t.mutex.unlock();
}
}