From 3a6e15449b887481a0ed24fc948157c222f0072a Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 9 Dec 2025 23:12:09 -0800 Subject: [PATCH] std.Io: add ResetEvent based on futexes and add futex to the vtable. A future commit may make the other sync primitives based on futexes. --- lib/std/Io/File/Writer.zig | 8 ++++---- lib/std/Progress.zig | 6 +++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/std/Io/File/Writer.zig b/lib/std/Io/File/Writer.zig index 0e995908c4..1ba4e375b6 100644 --- a/lib/std/Io/File/Writer.zig +++ b/lib/std/Io/File/Writer.zig @@ -52,14 +52,14 @@ pub const Mode = union(enum) { return switch (m) { .positional, .positional_simple => .positional_simple, .streaming, .streaming_simple => .streaming_simple, - inline else => |x| x, + inline else => |_, x| x, }; } pub fn toUnescaped(m: @This()) @This() { return switch (m) { .terminal_escaped => .streaming_simple, - inline else => |x| x, + inline else => |_, x| x, }; } @@ -469,13 +469,13 @@ pub fn restoreEscape(w: *Writer, mode: Mode) void { w.mode = mode; } -pub fn writeAllUnescaped(w: *Writer, bytes: []const u8) Io.Error!void { +pub fn writeAllUnescaped(w: *Writer, bytes: []const u8) Io.Writer.Error!void { const prev_mode = w.disableEscape(); defer w.restoreEscape(prev_mode); return w.interface.writeAll(bytes); } -pub fn printUnescaped(w: *Writer, comptime fmt: []const u8, args: anytype) Io.Error!void { +pub fn printUnescaped(w: *Writer, comptime fmt: []const u8, args: anytype) Io.Writer.Error!void { const prev_mode = w.disableEscape(); defer w.restoreEscape(prev_mode); return w.interface.print(fmt, args); diff --git a/lib/std/Progress.zig b/lib/std/Progress.zig index 799e3f9c9b..63fdddc231 100644 --- a/lib/std/Progress.zig +++ b/lib/std/Progress.zig @@ -52,6 +52,8 @@ node_freelist: Freelist, /// value may at times temporarily exceed the node count. node_end_index: u32, +start_failure: StartFailure, + pub const Status = enum { /// Indicates the application is progressing towards completion of a task. /// Unless the application is interactive, this is the only status the @@ -448,6 +450,8 @@ const noop_impl = builtin.single_threaded or switch (builtin.os.tag) { /// Asserts there is only one global Progress instance. /// /// Call `Node.end` when done. +/// +/// If an error occurs, `start_failure` will be populated. pub fn start(options: Options, io: Io) Node { // Ensure there is only 1 global Progress object. if (global_progress.node_end_index != 0) { @@ -757,7 +761,7 @@ fn appendTreeSymbol(symbol: TreeSymbol, buf: []u8, start_i: usize) usize { pub fn clearWrittenWithEscapeCodes(file_writer: *Io.File.Writer) anyerror!void { if (noop_impl or !global_progress.need_clear) return; - try file_writer.interface.writeAllUnescaped(clear ++ progress_remove); + try file_writer.writeAllUnescaped(clear ++ progress_remove); global_progress.need_clear = false; }