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. Private Function
fngroupAwait(userdata: ?*anyopaque, type_erased: *Io.Group, initial_token: *anyopaque) Io.Cancelable!void {
_ = initial_token; // we need to load `token` *after* the group finishesif (builtin.single_threaded) unreachable; // nothing to awaitconstt: *Threaded = @ptrCast(@alignCast(userdata));
constg: Group = .{ .ptr = type_erased };
varnum_completed: std.atomic.Value(u32) = .init(0);
g.awaiter().* = &num_completed;
constpre_await_status = g.status().fetchOr(.{
.num_running = 0,
.have_awaiter = true,
.canceled = false,
}, .acq_rel); // acquire results if complete; release `g.awaiter()`assert(!pre_await_status.have_awaiter);
assert(!pre_await_status.canceled);
if (pre_await_status.num_running == 0) {
// Already done. Since the group is finished, it's illegal to spawn more tasks in it// until we return, so we can access `g.status()` non-atomically.g.status().raw.have_awaiter = false;
return;
}
while (Thread.futexWait(&num_completed.raw, 0, null)) {
switch (num_completed.load(.acquire)) { // acquire task results0 => continue,
1 => break,
else => unreachable, // group was reused before `await` returned
}
} else |err| switch (err) {
error.Canceled => {
constpre_cancel_status = g.status().fetchOr(.{
.num_running = 0,
.have_awaiter = false,
.canceled = true,
}, .acq_rel); // acquire results if complete; release `g.awaiter()`assert(pre_cancel_status.have_awaiter);
assert(!pre_cancel_status.canceled);
// Even if `pre_cancel_status.num_running == 0`, we still need to wait for the signal,// because in that case the last member of the group is already trying to modify it.// However, if we know everything is done, we *can* skip signaling blocked threads.constskip_signals = pre_cancel_status.num_running == 0;
g.waitForCancelWithSignaling(t, &num_completed, skip_signals);
// The group is finished, so it's illegal to spawn more tasks in it until we return, so// we can access `g.status()` non-atomically.g.status().raw.canceled = false;
g.status().raw.have_awaiter = false;
returnerror.Canceled;
},
}
// The group is finished, so it's illegal to spawn more tasks in it until we return, so// we can access `g.status()` non-atomically.g.status().raw.have_awaiter = false;
}