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 {...@@ -1178,7 +1178,6 @@ pub fn Select(comptime U: type) type {
1178 io: Io,1178 io: Io,
1179 group: Group,1179 group: Group,
1180 queue: Queue(U),1180 queue: Queue(U),
1181 outstanding: usize,
11821181
1183 const S = @This();1182 const S = @This();
11841183
...@@ -1191,7 +1190,6 @@ pub fn Select(comptime U: type) type {...@@ -1191,7 +1190,6 @@ pub fn Select(comptime U: type) type {
1191 .io = io,1190 .io = io,
1192 .queue = .init(buffer),1191 .queue = .init(buffer),
1193 .group = .init,1192 .group = .init,
1194 .outstanding = 0,
1195 };1193 };
1196 }1194 }
11971195
...@@ -1235,7 +1233,6 @@ pub fn Select(comptime U: type) type {...@@ -1235,7 +1233,6 @@ pub fn Select(comptime U: type) type {
1235 }1233 }
1236 };1234 };
1237 const context: Context = .{ .select = s, .args = args };1235 const context: Context = .{ .select = s, .args = args };
1238 _ = @atomicRmw(usize, &s.outstanding, .Add, 1, .monotonic);
1239 s.io.vtable.groupAsync(s.io.userdata, &s.group, @ptrCast(&context), .of(Context), Context.start);1236 s.io.vtable.groupAsync(s.io.userdata, &s.group, @ptrCast(&context), .of(Context), Context.start);
1240 }1237 }
12411238
...@@ -1276,16 +1273,12 @@ pub fn Select(comptime U: type) type {...@@ -1276,16 +1273,12 @@ pub fn Select(comptime U: type) type {
1276 };1273 };
1277 const context: Context = .{ .select = s, .args = args };1274 const context: Context = .{ .select = s, .args = args };
1278 try s.io.vtable.groupConcurrent(s.io.userdata, &s.group, @ptrCast(&context), .of(Context), Context.start);1275 try s.io.vtable.groupConcurrent(s.io.userdata, &s.group, @ptrCast(&context), .of(Context), Context.start);
1279 _ = @atomicRmw(usize, &s.outstanding, .Add, 1, .monotonic);
1280 }1276 }
12811277
1282 /// Blocks until another task of the select finishes.1278 /// Blocks until another task of the select finishes.
1283 ///1279 ///
1284 /// Asserts there is at least one more `outstanding` task.
1285 ///
1286 /// Not threadsafe.1280 /// Not threadsafe.
1287 pub fn await(s: *S) Cancelable!U {1281 pub fn await(s: *S) Cancelable!U {
1288 s.outstanding -= 1;
1289 return s.queue.getOne(s.io) catch |err| switch (err) {1282 return s.queue.getOne(s.io) catch |err| switch (err) {
1290 error.Canceled => |e| return e,1283 error.Canceled => |e| return e,
1291 error.Closed => unreachable,1284 error.Closed => unreachable,
...@@ -1301,7 +1294,6 @@ pub fn Select(comptime U: type) type {...@@ -1301,7 +1294,6 @@ pub fn Select(comptime U: type) type {
1301 ///1294 ///
1302 /// Idempotent. Not threadsafe.1295 /// Idempotent. Not threadsafe.
1303 pub fn cancel(s: *S) void {1296 pub fn cancel(s: *S) void {
1304 s.outstanding = 0;
1305 s.group.cancel(s.io);1297 s.group.cancel(s.io);
1306 }1298 }
1307 };1299 };
lib/std/crypto/kangarootwelve.zig+4-1
...@@ -883,6 +883,7 @@ fn ktMultiThreaded(...@@ -883,6 +883,7 @@ fn ktMultiThreaded(
883 defer allocator.free(pending_cv_buf);883 defer allocator.free(pending_cv_buf);
884 var pending_cv_lens: [256]usize = .{0} ** 256;884 var pending_cv_lens: [256]usize = .{0} ** 256;
885885
886 var select_outstanding: usize = 0;
886 var select: Select = .init(io, select_buf);887 var select: Select = .init(io, select_buf);
887 defer select.cancel();888 defer select.cancel();
888 var batches_spawned: usize = 0;889 var batches_spawned: usize = 0;
...@@ -894,6 +895,7 @@ fn ktMultiThreaded(...@@ -894,6 +895,7 @@ fn ktMultiThreaded(
894 const batch_leaves = @min(leaves_per_batch, full_leaves - batch_start_leaf);895 const batch_leaves = @min(leaves_per_batch, full_leaves - batch_start_leaf);
895 const start_offset = chunk_size + batch_start_leaf * chunk_size;896 const start_offset = chunk_size + batch_start_leaf * chunk_size;
896897
898 select_outstanding += 1;
897 select.async(.batch, SelectLeafContext(Variant).process, .{SelectLeafContext(Variant){899 select.async(.batch, SelectLeafContext(Variant).process, .{SelectLeafContext(Variant){
898 .view = view,900 .view = view,
899 .batch_idx = batches_spawned,901 .batch_idx = batches_spawned,
...@@ -903,6 +905,7 @@ fn ktMultiThreaded(...@@ -903,6 +905,7 @@ fn ktMultiThreaded(
903 batches_spawned += 1;905 batches_spawned += 1;
904 }906 }
905907
908 select_outstanding -= 1;
906 const result = try select.await();909 const result = try select.await();
907 const batch = result.batch;910 const batch = result.batch;
908 const slot = batch.batch_idx % max_concurrent;911 const slot = batch.batch_idx % max_concurrent;
...@@ -927,7 +930,7 @@ fn ktMultiThreaded(...@@ -927,7 +930,7 @@ fn ktMultiThreaded(
927 }930 }
928 }931 }
929932
930 assert(select.outstanding == 0);933 assert(select_outstanding == 0);
931 }934 }
932935
933 if (has_partial_leaf) {936 if (has_partial_leaf) {