Zig 0.17.0-dev (Split by item) 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.
std › Progress › Node › end Public Function end Doc Source Public Function std.Progress.Node.end
pub fn end (n : Node ) void Params File Progress.zig: 370
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418 pub fn end (n : Node ) void {
if (noop_impl ) {
assert (n .index == .none );
return ;
}
const index = n .index .unwrap () orelse return ;
const io = global_progress .io ;
const parent_ptr = parentByIndex (index );
if (@atomicLoad (Node .Parent , parent_ptr , .monotonic ).unwrap ()) |parent_index | {
_ = @atomicRmw (u32 , &storageByIndex (parent_index ).completed_count , .Add , 1 , .monotonic );
@atomicStore (Node .Parent , parent_ptr , .unused , .monotonic );
if (storageByIndex (index ).getIpcIndex ()) |ipc_index | {
const file = global_progress .ipc_files [ipc_index .slot ];
const ipc = @atomicRmw (
Ipc ,
&global_progress .ipc [ipc_index .slot ],
.And ,
.{ .locked = true , .valid = false , .generation = std .math .maxInt (Ipc .Generation ) },
.release ,
);
assert (ipc .valid and ipc .generation == ipc_index .generation );
if (!ipc .locked ) file .close (io );
}
const freelist = &global_progress .node_freelist ;
var old_freelist = @atomicLoad (Freelist , freelist , .monotonic );
while (true ) {
@atomicStore (Node .OptionalIndex , freelistNextByIndex (index ), old_freelist .head , .monotonic );
old_freelist = @cmpxchgWeak (
Freelist ,
freelist ,
old_freelist ,
.{ .head = index .toOptional (), .generation = old_freelist .generation +% 1 },
.release , // ensure a matching `start` sees the freelist link written above
.monotonic , // our write above is irrelevant if we need to retry
) orelse {
// We won the race.
return ;
};
}
} else {
if (global_progress .update_worker ) |*worker | worker .cancel (io ) catch {};
for (&global_progress .ipc , &global_progress .ipc_files ) |ipc , ipc_file | {
assert (!ipc .locked or !ipc .valid ); // missing call to end()
if (ipc .locked or ipc .valid ) ipc_file .close (io );
}
}
}
Finish a started
Node. Thread-safe.