fn batchCancel(userdata: ?*anyopaque, batch: *Io.Batch) void userdata: ?*anyopaquebatch: *Io.Batch1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000fn batchCancel(userdata: ?*anyopaque, batch: *Io.Batch) void {
const ev: *Evented = @ptrCast(@alignCast(userdata));
var index = batch.pending.head;
while (index != .none) {
const storage = &batch.storage[index.toIndex()];
const pending = &storage.pending;
const operation_userdata: *BatchOperationUserdata = .fromErased(&pending.userdata);
assert(operation_userdata.batch == batch);
operation_userdata.source.cancel();
}
const queue: c.dispatch.queue_t = @ptrCast(batch.userdata orelse return);
if (batch.pending.head != .none) {
var waiter: BatchWaiter = .{
.sleeper = .init(ev.queue, Thread.current().currentFiber()),
.queue = queue,
.timer = BatchWaiter.already_signaled,
};
if (batch.pending.head == .none) queue.async(&waiter, &BatchWaiter.signal);
queue.as_object().set_context(&waiter);
ev.yield(.{ .@"resume" = queue.as_object() });
}
batch.userdata = null;
}