Function end [src]

Finish a started Node. Thread-safe.

Prototype

pub fn end(n: Node) void

Parameters

n: Node

Source

pub fn end(n: Node) void { if (noop_impl) { assert(n.index == .none); return; } const index = n.index.unwrap() orelse return; 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); 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 { @atomicStore(bool, &global_progress.done, true, .monotonic); global_progress.redraw_event.set(); if (global_progress.update_thread) |thread| thread.join(); } }