authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-02-20 16:42:37-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-02-20 16:42:37-08:00
log54eb03cbf61a5c5fdee29c0f45cca824e13d6af8
treeeb8457fdaab9f88033367baace948a0d59159813
parent5ac6ff43d41f23d7d215c3164848bb4ffcf00d59

std.Io.Select: remove "outstanding" field

it is not fundamentally part of this abstraction

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

lib/std/Io.zig-8
......@@ -1178,7 +1178,6 @@ pub fn Select(comptime U: type) type {
11781178 io: Io,
11791179 group: Group,
11801180 queue: Queue(U),
1181 outstanding: usize,
11821181
11831182 const S = @This();
11841183
......@@ -1191,7 +1190,6 @@ pub fn Select(comptime U: type) type {
11911190 .io = io,
11921191 .queue = .init(buffer),
11931192 .group = .init,
1194 .outstanding = 0,
11951193 };
11961194 }
11971195
......@@ -1235,7 +1233,6 @@ pub fn Select(comptime U: type) type {
12351233 }
12361234 };
12371235 const context: Context = .{ .select = s, .args = args };
1238 _ = @atomicRmw(usize, &s.outstanding, .Add, 1, .monotonic);
12391236 s.io.vtable.groupAsync(s.io.userdata, &s.group, @ptrCast(&context), .of(Context), Context.start);
12401237 }
12411238
......@@ -1276,16 +1273,12 @@ pub fn Select(comptime U: type) type {
12761273 };
12771274 const context: Context = .{ .select = s, .args = args };
12781275 try s.io.vtable.groupConcurrent(s.io.userdata, &s.group, @ptrCast(&context), .of(Context), Context.start);
1279 _ = @atomicRmw(usize, &s.outstanding, .Add, 1, .monotonic);
12801276 }
12811277
12821278 /// Blocks until another task of the select finishes.
12831279 ///
1284 /// Asserts there is at least one more `outstanding` task.
1285 ///
12861280 /// Not threadsafe.
12871281 pub fn await(s: *S) Cancelable!U {
1288 s.outstanding -= 1;
12891282 return s.queue.getOne(s.io) catch |err| switch (err) {
12901283 error.Canceled => |e| return e,
12911284 error.Closed => unreachable,
......@@ -1301,7 +1294,6 @@ pub fn Select(comptime U: type) type {
13011294 ///
13021295 /// Idempotent. Not threadsafe.
13031296 pub fn cancel(s: *S) void {
1304 s.outstanding = 0;
13051297 s.group.cancel(s.io);
13061298 }
13071299 };
lib/std/crypto/kangarootwelve.zig+4-1
......@@ -883,6 +883,7 @@ fn ktMultiThreaded(
883883 defer allocator.free(pending_cv_buf);
884884 var pending_cv_lens: [256]usize = .{0} ** 256;
885885
886 var select_outstanding: usize = 0;
886887 var select: Select = .init(io, select_buf);
887888 defer select.cancel();
888889 var batches_spawned: usize = 0;
......@@ -894,6 +895,7 @@ fn ktMultiThreaded(
894895 const batch_leaves = @min(leaves_per_batch, full_leaves - batch_start_leaf);
895896 const start_offset = chunk_size + batch_start_leaf * chunk_size;
896897
898 select_outstanding += 1;
897899 select.async(.batch, SelectLeafContext(Variant).process, .{SelectLeafContext(Variant){
898900 .view = view,
899901 .batch_idx = batches_spawned,
......@@ -903,6 +905,7 @@ fn ktMultiThreaded(
903905 batches_spawned += 1;
904906 }
905907
908 select_outstanding -= 1;
906909 const result = try select.await();
907910 const batch = result.batch;
908911 const slot = batch.batch_idx % max_concurrent;
......@@ -927,7 +930,7 @@ fn ktMultiThreaded(
927930 }
928931 }
929932
930 assert(select.outstanding == 0);
933 assert(select_outstanding == 0);
931934 }
932935
933936 if (has_partial_leaf) {