commit e366b13a6573979bf4e644374aaf3e3b125a6377 (tree)
parent 4063205746efec752faaece85355c01de55ef08e
Author: Jacob Young <jacobly0@users.noreply.github.com>
Date: Mon, 31 Mar 2025 23:45:31 -0400
EventLoop: revert incorrect optimization
Diffstat:
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/lib/std/Io/EventLoop.zig b/lib/std/Io/EventLoop.zig
@@ -248,8 +248,16 @@ fn findReadyFiber(el: *EventLoop, thread: *Thread) ?*Fiber {
if (thread.steal_ready_search_index == active_threads) thread.steal_ready_search_index = 0;
const steal_ready_search_thread = &el.threads.allocated[0..active_threads][thread.steal_ready_search_index];
if (steal_ready_search_thread == thread) continue;
- const ready_fiber = @atomicRmw(?*Fiber, &steal_ready_search_thread.ready_queue, .And, Fiber.finished, .acquire) orelse continue;
+ const ready_fiber = @atomicLoad(?*Fiber, &steal_ready_search_thread.ready_queue, .acquire) orelse continue;
if (ready_fiber == Fiber.finished) continue;
+ if (@cmpxchgWeak(
+ ?*Fiber,
+ &steal_ready_search_thread.ready_queue,
+ ready_fiber,
+ null,
+ .acquire,
+ .monotonic,
+ )) |_| continue;
@atomicStore(?*Fiber, &thread.ready_queue, ready_fiber.queue_next, .release);
ready_fiber.queue_next = null;
return ready_fiber;
@@ -297,7 +305,7 @@ fn schedule(el: *EventLoop, thread: *Thread, ready_queue: Fiber.Queue) void {
&idle_search_thread.ready_queue,
null,
ready_queue.head,
- .acq_rel,
+ .release,
.monotonic,
)) |_| continue;
getSqe(&thread.io_uring).* = .{
@@ -1268,9 +1276,9 @@ fn conditionWait(userdata: ?*anyopaque, cond: *Io.Condition, mutex: *Io.Mutex) I
const fiber = thread.currentFiber();
const prev = @atomicRmw(?*Fiber, cond_state, .Xchg, fiber, .acquire);
assert(prev == null); // More than one wait on same Condition is illegal.
- mutex.unlock(io(el));
+ mutex.unlock(el.io());
el.yield(null, .nothing);
- try mutex.lock(io(el));
+ try mutex.lock(el.io());
}
fn conditionWake(userdata: ?*anyopaque, cond: *Io.Condition) void {