authorgravatar for bilal@evercam.ioBillal GHILAS <bilal@evercam.io> 2026-07-16 11:26:11+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-10-21 12:54:52-07:00
logae7f9deb167f85a755d1a1036cfe46da7fa76b9b
treea846398e6b3162cefdec5aa936e77b1aad07e3f3
parentae7b2ba9e3d43fc058ef2faadfceda77e2018f19

std.Io.Threaded.batchAwaitConcurrent: fix eager path


1 files changed, 19 insertions(+), 3 deletions(-)

lib/std/Io/Threaded.zig+19-3
......@@ -2868,10 +2868,14 @@ fn batchAwaitConcurrent(userdata: ?*anyopaque, b: *Io.Batch, timeout: Io.Timeout
28682868 }
28692869 } = .{ .gpa = t.allocator, .batch = b, .slice = &poll_buffer, .len = 0 };
28702870 {
2871 var prev_index: Io.Operation.OptionalIndex = .none;
28712872 var index = b.submitted.head;
28722873 while (index != .none) {
28732874 const storage = &b.storage[index.toIndex()];
28742875 const submission = storage.submission;
2876 const next_index = submission.node.next;
2877 defer index = next_index;
2878
28752879 switch (submission.operation) {
28762880 .file_read_streaming => |o| try poll_storage.add(o.file.handle, posix.POLL.IN | posix.POLL.ERR),
28772881 .file_write_streaming => |o| try poll_storage.add(o.file.handle, posix.POLL.OUT | posix.POLL.ERR),
......@@ -2891,12 +2895,18 @@ fn batchAwaitConcurrent(userdata: ?*anyopaque, b: *Io.Batch, timeout: Io.Timeout
28912895 };
28922896 data_i += msg.data.len;
28932897 } else .{ null, o.message_buffer.len } };
2898 switch (prev_index) {
2899 .none => b.submitted.head = next_index,
2900 else => b.storage[prev_index.toIndex()].submission.node.next = next_index,
2901 }
2902 if (next_index == .none) b.submitted.tail = prev_index;
28942903 switch (b.completed.tail) {
28952904 .none => b.completed.head = index,
28962905 else => |tail_index| b.storage[tail_index.toIndex()].completion.node.next = index,
28972906 }
2898 storage.* = .{ .completion = .{ .node = .{ .next = .none }, .result = result } };
28992907 b.completed.tail = index;
2908 storage.* = .{ .completion = .{ .node = .{ .next = .none }, .result = result } };
2909 continue;
29002910 },
29012911 .net_send => |*o| nb: {
29022912 const result: Io.Operation.Result = .{
......@@ -2920,18 +2930,24 @@ fn batchAwaitConcurrent(userdata: ?*anyopaque, b: *Io.Batch, timeout: Io.Timeout
29202930 break :o .{ null, sent };
29212931 },
29222932 };
2933 switch (prev_index) {
2934 .none => b.submitted.head = next_index,
2935 else => b.storage[prev_index.toIndex()].submission.node.next = next_index,
2936 }
2937 if (next_index == .none) b.submitted.tail = prev_index;
29232938 switch (b.completed.tail) {
29242939 .none => b.completed.head = index,
29252940 else => |tail_index| b.storage[tail_index.toIndex()].completion.node.next = index,
29262941 }
2927 storage.* = .{ .completion = .{ .node = .{ .next = .none }, .result = result } };
29282942 b.completed.tail = index;
2943 storage.* = .{ .completion = .{ .node = .{ .next = .none }, .result = result } };
2944 continue;
29292945 },
29302946 .net_accept => |o| try poll_storage.add(o.socket_handle, posix.POLL.IN | posix.POLL.ERR),
29312947 .net_read => |o| try poll_storage.add(o.socket_handle, posix.POLL.IN | posix.POLL.ERR),
29322948 .net_write => |o| try poll_storage.add(o.socket_handle, posix.POLL.OUT | posix.POLL.ERR),
29332949 }
2934 index = submission.node.next;
2950 prev_index = index;
29352951 }
29362952 }
29372953 switch (poll_storage.len) {