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...@@ -2868,10 +2868,14 @@ fn batchAwaitConcurrent(userdata: ?*anyopaque, b: *Io.Batch, timeout: Io.Timeout
2868 }2868 }
2869 } = .{ .gpa = t.allocator, .batch = b, .slice = &poll_buffer, .len = 0 };2869 } = .{ .gpa = t.allocator, .batch = b, .slice = &poll_buffer, .len = 0 };
2870 {2870 {
2871 var prev_index: Io.Operation.OptionalIndex = .none;
2871 var index = b.submitted.head;2872 var index = b.submitted.head;
2872 while (index != .none) {2873 while (index != .none) {
2873 const storage = &b.storage[index.toIndex()];2874 const storage = &b.storage[index.toIndex()];
2874 const submission = storage.submission;2875 const submission = storage.submission;
2876 const next_index = submission.node.next;
2877 defer index = next_index;
2878
2875 switch (submission.operation) {2879 switch (submission.operation) {
2876 .file_read_streaming => |o| try poll_storage.add(o.file.handle, posix.POLL.IN | posix.POLL.ERR),2880 .file_read_streaming => |o| try poll_storage.add(o.file.handle, posix.POLL.IN | posix.POLL.ERR),
2877 .file_write_streaming => |o| try poll_storage.add(o.file.handle, posix.POLL.OUT | posix.POLL.ERR),2881 .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...@@ -2891,12 +2895,18 @@ fn batchAwaitConcurrent(userdata: ?*anyopaque, b: *Io.Batch, timeout: Io.Timeout
2891 };2895 };
2892 data_i += msg.data.len;2896 data_i += msg.data.len;
2893 } else .{ null, o.message_buffer.len } };2897 } 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;
2894 switch (b.completed.tail) {2903 switch (b.completed.tail) {
2895 .none => b.completed.head = index,2904 .none => b.completed.head = index,
2896 else => |tail_index| b.storage[tail_index.toIndex()].completion.node.next = index,2905 else => |tail_index| b.storage[tail_index.toIndex()].completion.node.next = index,
2897 }2906 }
2898 storage.* = .{ .completion = .{ .node = .{ .next = .none }, .result = result } };
2899 b.completed.tail = index;2907 b.completed.tail = index;
2908 storage.* = .{ .completion = .{ .node = .{ .next = .none }, .result = result } };
2909 continue;
2900 },2910 },
2901 .net_send => |*o| nb: {2911 .net_send => |*o| nb: {
2902 const result: Io.Operation.Result = .{2912 const result: Io.Operation.Result = .{
...@@ -2920,18 +2930,24 @@ fn batchAwaitConcurrent(userdata: ?*anyopaque, b: *Io.Batch, timeout: Io.Timeout...@@ -2920,18 +2930,24 @@ fn batchAwaitConcurrent(userdata: ?*anyopaque, b: *Io.Batch, timeout: Io.Timeout
2920 break :o .{ null, sent };2930 break :o .{ null, sent };
2921 },2931 },
2922 };2932 };
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;
2923 switch (b.completed.tail) {2938 switch (b.completed.tail) {
2924 .none => b.completed.head = index,2939 .none => b.completed.head = index,
2925 else => |tail_index| b.storage[tail_index.toIndex()].completion.node.next = index,2940 else => |tail_index| b.storage[tail_index.toIndex()].completion.node.next = index,
2926 }2941 }
2927 storage.* = .{ .completion = .{ .node = .{ .next = .none }, .result = result } };
2928 b.completed.tail = index;2942 b.completed.tail = index;
2943 storage.* = .{ .completion = .{ .node = .{ .next = .none }, .result = result } };
2944 continue;
2929 },2945 },
2930 .net_accept => |o| try poll_storage.add(o.socket_handle, posix.POLL.IN | posix.POLL.ERR),2946 .net_accept => |o| try poll_storage.add(o.socket_handle, posix.POLL.IN | posix.POLL.ERR),
2931 .net_read => |o| try poll_storage.add(o.socket_handle, posix.POLL.IN | posix.POLL.ERR),2947 .net_read => |o| try poll_storage.add(o.socket_handle, posix.POLL.IN | posix.POLL.ERR),
2932 .net_write => |o| try poll_storage.add(o.socket_handle, posix.POLL.OUT | posix.POLL.ERR),2948 .net_write => |o| try poll_storage.add(o.socket_handle, posix.POLL.OUT | posix.POLL.ERR),
2933 }2949 }
2934 index = submission.node.next;2950 prev_index = index;
2935 }2951 }
2936 }2952 }
2937 switch (poll_storage.len) {2953 switch (poll_storage.len) {