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) {...@@ -52,14 +52,14 @@ pub const Mode = union(enum) {
52 return switch (m) {52 return switch (m) {
53 .positional, .positional_simple => .positional_simple,53 .positional, .positional_simple => .positional_simple,
54 .streaming, .streaming_simple => .streaming_simple,54 .streaming, .streaming_simple => .streaming_simple,
55 inline else => |x| x,55 inline else => |_, x| x,
56 };56 };
57 }57 }
5858
59 pub fn toUnescaped(m: @This()) @This() {59 pub fn toUnescaped(m: @This()) @This() {
60 return switch (m) {60 return switch (m) {
61 .terminal_escaped => .streaming_simple,61 .terminal_escaped => .streaming_simple,
62 inline else => |x| x,62 inline else => |_, x| x,
63 };63 };
64 }64 }
6565
...@@ -469,13 +469,13 @@ pub fn restoreEscape(w: *Writer, mode: Mode) void {...@@ -469,13 +469,13 @@ pub fn restoreEscape(w: *Writer, mode: Mode) void {
469 w.mode = mode;469 w.mode = mode;
470}470}
471471
472pub fn writeAllUnescaped(w: *Writer, bytes: []const u8) Io.Error!void {472pub fn writeAllUnescaped(w: *Writer, bytes: []const u8) Io.Writer.Error!void {
473 const prev_mode = w.disableEscape();473 const prev_mode = w.disableEscape();
474 defer w.restoreEscape(prev_mode);474 defer w.restoreEscape(prev_mode);
475 return w.interface.writeAll(bytes);475 return w.interface.writeAll(bytes);
476}476}
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 {
479 const prev_mode = w.disableEscape();479 const prev_mode = w.disableEscape();
480 defer w.restoreEscape(prev_mode);480 defer w.restoreEscape(prev_mode);
481 return w.interface.print(fmt, args);481 return w.interface.print(fmt, args);
lib/std/Progress.zig+5-1
...@@ -52,6 +52,8 @@ node_freelist: Freelist,...@@ -52,6 +52,8 @@ node_freelist: Freelist,
52/// value may at times temporarily exceed the node count.52/// value may at times temporarily exceed the node count.
53node_end_index: u32,53node_end_index: u32,
5454
55start_failure: StartFailure,
56
55pub const Status = enum {57pub const Status = enum {
56 /// Indicates the application is progressing towards completion of a task.58 /// Indicates the application is progressing towards completion of a task.
57 /// Unless the application is interactive, this is the only status the59 /// 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) {...@@ -448,6 +450,8 @@ const noop_impl = builtin.single_threaded or switch (builtin.os.tag) {
448/// Asserts there is only one global Progress instance.450/// Asserts there is only one global Progress instance.
449///451///
450/// Call `Node.end` when done.452/// Call `Node.end` when done.
453///
454/// If an error occurs, `start_failure` will be populated.
451pub fn start(options: Options, io: Io) Node {455pub fn start(options: Options, io: Io) Node {
452 // Ensure there is only 1 global Progress object.456 // Ensure there is only 1 global Progress object.
453 if (global_progress.node_end_index != 0) {457 if (global_progress.node_end_index != 0) {
...@@ -757,7 +761,7 @@ fn appendTreeSymbol(symbol: TreeSymbol, buf: []u8, start_i: usize) usize {...@@ -757,7 +761,7 @@ fn appendTreeSymbol(symbol: TreeSymbol, buf: []u8, start_i: usize) usize {
757761
758pub fn clearWrittenWithEscapeCodes(file_writer: *Io.File.Writer) anyerror!void {762pub fn clearWrittenWithEscapeCodes(file_writer: *Io.File.Writer) anyerror!void {
759 if (noop_impl or !global_progress.need_clear) return;763 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);
761 global_progress.need_clear = false;765 global_progress.need_clear = false;
762}766}
763767