mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-03-08 01:04:43 +01:00
std.Io.Select: remove "outstanding" field
it is not fundamentally part of this abstraction
This commit is contained in:
parent
5ac6ff43d4
commit
54eb03cbf6
2 changed files with 4 additions and 9 deletions
|
|
@ -1178,7 +1178,6 @@ pub fn Select(comptime U: type) type {
|
|||
io: Io,
|
||||
group: Group,
|
||||
queue: Queue(U),
|
||||
outstanding: usize,
|
||||
|
||||
const S = @This();
|
||||
|
||||
|
|
@ -1191,7 +1190,6 @@ pub fn Select(comptime U: type) type {
|
|||
.io = io,
|
||||
.queue = .init(buffer),
|
||||
.group = .init,
|
||||
.outstanding = 0,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -1235,7 +1233,6 @@ pub fn Select(comptime U: type) type {
|
|||
}
|
||||
};
|
||||
const context: Context = .{ .select = s, .args = args };
|
||||
_ = @atomicRmw(usize, &s.outstanding, .Add, 1, .monotonic);
|
||||
s.io.vtable.groupAsync(s.io.userdata, &s.group, @ptrCast(&context), .of(Context), Context.start);
|
||||
}
|
||||
|
||||
|
|
@ -1276,16 +1273,12 @@ pub fn Select(comptime U: type) type {
|
|||
};
|
||||
const context: Context = .{ .select = s, .args = args };
|
||||
try s.io.vtable.groupConcurrent(s.io.userdata, &s.group, @ptrCast(&context), .of(Context), Context.start);
|
||||
_ = @atomicRmw(usize, &s.outstanding, .Add, 1, .monotonic);
|
||||
}
|
||||
|
||||
/// Blocks until another task of the select finishes.
|
||||
///
|
||||
/// Asserts there is at least one more `outstanding` task.
|
||||
///
|
||||
/// Not threadsafe.
|
||||
pub fn await(s: *S) Cancelable!U {
|
||||
s.outstanding -= 1;
|
||||
return s.queue.getOne(s.io) catch |err| switch (err) {
|
||||
error.Canceled => |e| return e,
|
||||
error.Closed => unreachable,
|
||||
|
|
@ -1301,7 +1294,6 @@ pub fn Select(comptime U: type) type {
|
|||
///
|
||||
/// Idempotent. Not threadsafe.
|
||||
pub fn cancel(s: *S) void {
|
||||
s.outstanding = 0;
|
||||
s.group.cancel(s.io);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -883,6 +883,7 @@ fn ktMultiThreaded(
|
|||
defer allocator.free(pending_cv_buf);
|
||||
var pending_cv_lens: [256]usize = .{0} ** 256;
|
||||
|
||||
var select_outstanding: usize = 0;
|
||||
var select: Select = .init(io, select_buf);
|
||||
defer select.cancel();
|
||||
var batches_spawned: usize = 0;
|
||||
|
|
@ -894,6 +895,7 @@ fn ktMultiThreaded(
|
|||
const batch_leaves = @min(leaves_per_batch, full_leaves - batch_start_leaf);
|
||||
const start_offset = chunk_size + batch_start_leaf * chunk_size;
|
||||
|
||||
select_outstanding += 1;
|
||||
select.async(.batch, SelectLeafContext(Variant).process, .{SelectLeafContext(Variant){
|
||||
.view = view,
|
||||
.batch_idx = batches_spawned,
|
||||
|
|
@ -903,6 +905,7 @@ fn ktMultiThreaded(
|
|||
batches_spawned += 1;
|
||||
}
|
||||
|
||||
select_outstanding -= 1;
|
||||
const result = try select.await();
|
||||
const batch = result.batch;
|
||||
const slot = batch.batch_idx % max_concurrent;
|
||||
|
|
@ -927,7 +930,7 @@ fn ktMultiThreaded(
|
|||
}
|
||||
}
|
||||
|
||||
assert(select.outstanding == 0);
|
||||
assert(select_outstanding == 0);
|
||||
}
|
||||
|
||||
if (has_partial_leaf) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue