authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-09 23:12:09-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-23 22:15:09-08:00
log3a6e15449b887481a0ed24fc948157c222f0072a
treefcc688ff1a7ce513afc46703bfd2765adcdc3ebb
parentffcbd48a1220ce6d652ee762001d88baa385de49

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.

2 files changed, 9 insertions(+), 5 deletions(-)

lib/std/Io/File/Writer.zig+4-4
......@@ -52,14 +52,14 @@ pub const Mode = union(enum) {
5252 return switch (m) {
5353 .positional, .positional_simple => .positional_simple,
5454 .streaming, .streaming_simple => .streaming_simple,
55 inline else => |x| x,
55 inline else => |_, x| x,
5656 };
5757 }
5858
5959 pub fn toUnescaped(m: @This()) @This() {
6060 return switch (m) {
6161 .terminal_escaped => .streaming_simple,
62 inline else => |x| x,
62 inline else => |_, x| x,
6363 };
6464 }
6565
......@@ -469,13 +469,13 @@ pub fn restoreEscape(w: *Writer, mode: Mode) void {
469469 w.mode = mode;
470470}
471471
472pub fn writeAllUnescaped(w: *Writer, bytes: []const u8) Io.Error!void {
472pub fn writeAllUnescaped(w: *Writer, bytes: []const u8) Io.Writer.Error!void {
473473 const prev_mode = w.disableEscape();
474474 defer w.restoreEscape(prev_mode);
475475 return w.interface.writeAll(bytes);
476476}
477477
478pub fn printUnescaped(w: *Writer, comptime fmt: []const u8, args: anytype) Io.Error!void {
478pub fn printUnescaped(w: *Writer, comptime fmt: []const u8, args: anytype) Io.Writer.Error!void {
479479 const prev_mode = w.disableEscape();
480480 defer w.restoreEscape(prev_mode);
481481 return w.interface.print(fmt, args);
lib/std/Progress.zig+5-1
......@@ -52,6 +52,8 @@ node_freelist: Freelist,
5252/// value may at times temporarily exceed the node count.
5353node_end_index: u32,
5454
55start_failure: StartFailure,
56
5557pub const Status = enum {
5658 /// Indicates the application is progressing towards completion of a task.
5759 /// 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) {
448450/// Asserts there is only one global Progress instance.
449451///
450452/// Call `Node.end` when done.
453///
454/// If an error occurs, `start_failure` will be populated.
451455pub fn start(options: Options, io: Io) Node {
452456 // Ensure there is only 1 global Progress object.
453457 if (global_progress.node_end_index != 0) {
......@@ -757,7 +761,7 @@ fn appendTreeSymbol(symbol: TreeSymbol, buf: []u8, start_i: usize) usize {
757761
758762pub fn clearWrittenWithEscapeCodes(file_writer: *Io.File.Writer) anyerror!void {
759763 if (noop_impl or !global_progress.need_clear) return;
760 try file_writer.interface.writeAllUnescaped(clear ++ progress_remove);
764 try file_writer.writeAllUnescaped(clear ++ progress_remove);
761765 global_progress.need_clear = false;
762766}
763767