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
fnputLocked(q: *TypeErasedQueue, io: Io, elements: []constu8, min: usize, uncancelable: bool) (QueueClosedError || Cancelable)!usize {
// A closed queue cannot be added to, even if there is space in the buffer.if (q.closed) returnerror.Closed;
// Getters have first priority on the data, and only when the getters// queue is empty do we start populating the buffer.// The number of elements we add immediately, before possibly blocking.varn: usize = 0;
while (q.getters.popFirst()) |getter_node| {
constgetter: *Get = @alignCast(@fieldParentPtr("node", getter_node));
constcopy_len = @min(getter.remaining.len, elements.len - n);
assert(copy_len > 0);
@memcpy(getter.remaining[0..copy_len], elements[n..][0..copy_len]);
getter.remaining = getter.remaining[copy_len..];
getter.needed -|= copy_len;
n += copy_len;
if (getter.needed == 0) {
getter.condition.signal(io);
} else {
assert(n == elements.len); // we didn't have enough elements for the getterq.getters.prepend(getter_node);
}
if (n == elements.len) returnelements.len;
}
while (q.puttableSlice()) |slice| {
constcopy_len = @min(slice.len, elements.len - n);
assert(copy_len > 0);
@memcpy(slice[0..copy_len], elements[n..][0..copy_len]);
q.len += copy_len;
n += copy_len;
if (n == elements.len) returnelements.len;
}
// Don't block if we hit the min.if (n >= min) returnn;
varpending: Put = .{
.remaining = elements[n..],
.needed = min - n,
.condition = .init,
.node = .{},
};
q.putters.append(&pending.node);
deferif (pending.needed > 0) q.putters.remove(&pending.node);
while (pending.needed > 0and !q.closed) {
if (uncancelable) {
pending.condition.waitUncancelable(io, &q.mutex);
continue;
}
pending.condition.wait(io, &q.mutex) catch |err| switch (err) {
error.Canceled => if (pending.remaining.len == elements.len) {
// Canceled while waiting, and appended no elements.returnerror.Canceled;
} else {
// Canceled while waiting, but appended some elements, so report those first.io.recancel();
returnelements.len - pending.remaining.len;
},
};
}
if (pending.remaining.len == elements.len) {
// The queue was closed while we were waiting. We appended no elements.assert(q.closed);
returnerror.Closed;
}
returnelements.len - pending.remaining.len;
}