DoxigAlpha

end

Finish a started Node. Thread-safe.

Function parameters

Parameters

#

Type definitions in this namespace

Types

#
Node
Represents one unit of progress.

Initializes a global Progress instance.

Functions

#
start
Initializes a global Progress instance.
lockStdErr
Allows the caller to freely write to stderr until `unlockStdErr` is called.
lockStderrWriter
Allows the caller to freely write to the returned `Writer`,

= switch (builtin.os.tag) { .wasi, .freestanding, .windows => false, else => true, }

Values

#
have_ipc
= switch (builtin.os.tag) { .wasi, .freestanding, .windows => false, else => true, }

Source

Implementation

#
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();
    }
}