authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-06-16 19:27:49-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-06-16 19:27:49-07:00
log20e20f9238b1f4537a8186d80afbdf7516e127f6
treebaabc53ee48aafa521542c2d3608c617c1fbac76
parent17f14e1d65b59ebb1a8b5b617cc31fb2614f0c6a

std.Progress.Node: add `none` init value


1 files changed, 11 insertions(+), 9 deletions(-)

lib/std/Progress.zig+11-9
......@@ -80,6 +80,8 @@ pub const Options = struct {
8080pub const Node = struct {
8181 index: OptionalIndex,
8282
83 pub const none: Node = .{ .index = .none };
84
8385 pub const max_name_len = 40;
8486
8587 const Storage = extern struct {
......@@ -177,9 +179,9 @@ pub const Node = struct {
177179 pub fn start(node: Node, name: []const u8, estimated_total_items: usize) Node {
178180 if (noop_impl) {
179181 assert(node.index == .none);
180 return .{ .index = .none };
182 return Node.none;
181183 }
182 const node_index = node.index.unwrap() orelse return .{ .index = .none };
184 const node_index = node.index.unwrap() orelse return Node.none;
183185 const parent = node_index.toParent();
184186
185187 const freelist_head = &global_progress.node_freelist_first;
......@@ -196,7 +198,7 @@ pub const Node = struct {
196198 if (free_index >= global_progress.node_storage.len) {
197199 // Ran out of node storage memory. Progress for this node will not be tracked.
198200 _ = @atomicRmw(u32, &global_progress.node_end_index, .Sub, 1, .monotonic);
199 return .{ .index = .none };
201 return Node.none;
200202 }
201203
202204 return init(@enumFromInt(free_index), parent, name, estimated_total_items);
......@@ -357,7 +359,7 @@ pub fn start(options: Options) Node {
357359 global_progress.initial_delay_ns = options.initial_delay_ns;
358360
359361 if (noop_impl)
360 return .{ .index = .none };
362 return Node.none;
361363
362364 if (std.process.parseEnvVarInt("ZIG_PROGRESS", u31, 10)) |ipc_fd| {
363365 global_progress.update_thread = std.Thread.spawn(.{}, ipcThreadRun, .{
......@@ -368,12 +370,12 @@ pub fn start(options: Options) Node {
368370 }),
369371 }) catch |err| {
370372 std.log.warn("failed to spawn IPC thread for communicating progress to parent: {s}", .{@errorName(err)});
371 return .{ .index = .none };
373 return Node.none;
372374 };
373375 } else |env_err| switch (env_err) {
374376 error.EnvironmentVariableNotFound => {
375377 if (options.disable_printing) {
376 return .{ .index = .none };
378 return Node.none;
377379 }
378380 const stderr = std.io.getStdErr();
379381 global_progress.terminal = stderr;
......@@ -386,7 +388,7 @@ pub fn start(options: Options) Node {
386388 }
387389
388390 if (global_progress.terminal_mode == .off) {
389 return .{ .index = .none };
391 return Node.none;
390392 }
391393
392394 if (have_sigwinch) {
......@@ -408,12 +410,12 @@ pub fn start(options: Options) Node {
408410 global_progress.update_thread = thread;
409411 } else |err| {
410412 std.log.warn("unable to spawn thread for printing progress to terminal: {s}", .{@errorName(err)});
411 return .{ .index = .none };
413 return Node.none;
412414 }
413415 },
414416 else => |e| {
415417 std.log.warn("invalid ZIG_PROGRESS file descriptor integer: {s}", .{@errorName(e)});
416 return .{ .index = .none };
418 return Node.none;
417419 },
418420 }
419421