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
pubfnsetIpcFile(node: Node, expected_io_userdata: ?*anyopaque, file: Io.File) void {
constindex = node.index.unwrap() orelsereturn;
constio = global_progress.io;
assert(io.userdata == expected_io_userdata);
for (0..ipc_storage_buffer_len) |_| {
constslot: Ipc.Slot = @truncate(
@atomicRmw(Ipc.SlotAtomic, &global_progress.ipc_next, .Add, 1, .monotonic),
);
if (slot >= ipc_storage_buffer_len) continue;
constipc_ptr = &global_progress.ipc[slot];
constipc = @atomicLoad(Ipc, ipc_ptr, .monotonic);
if (ipc.lockedoripc.valid) continue;
constgeneration = ipc.generation +% 1;
if (@cmpxchgWeak(
Ipc,
ipc_ptr,
ipc,
.{ .locked = false, .valid = true, .generation = generation },
.acquire,
.monotonic,
)) |_| continue;
global_progress.ipc_files[slot] = file;
storageByIndex(index).setIpcIndex(.{ .slot = slot, .generation = generation });
break;
} else {
// There was no IPC slot available, so we'll drop this node's IPC info and just close// the fd. To avoid an old `estimated_total_items` or `completed_count` value still// being rendered for the node, we'll zero that field out (and the user is not allowed// to change it because they think we're doing IPC).file.close(io);
@atomicStore(u32, &storageByIndex(index).completed_count, 0, .monotonic);
@atomicStore(u32, &storageByIndex(index).estimated_total_count, 0, .monotonic);
}
}
Used by
std.process.Child. Thread-safe.