authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2025-03-31 23:45:31-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-10-29 06:20:48-07:00
loge366b13a6573979bf4e644374aaf3e3b125a6377
tree3104fd15e3d6b30551c2729b6930c011f34d869d
parent4063205746efec752faaece85355c01de55ef08e

EventLoop: revert incorrect optimization


1 files changed, 12 insertions(+), 4 deletions(-)

lib/std/Io/EventLoop.zig+12-4
......@@ -248,8 +248,16 @@ fn findReadyFiber(el: *EventLoop, thread: *Thread) ?*Fiber {
248248 if (thread.steal_ready_search_index == active_threads) thread.steal_ready_search_index = 0;
249249 const steal_ready_search_thread = &el.threads.allocated[0..active_threads][thread.steal_ready_search_index];
250250 if (steal_ready_search_thread == thread) continue;
251 const ready_fiber = @atomicRmw(?*Fiber, &steal_ready_search_thread.ready_queue, .And, Fiber.finished, .acquire) orelse continue;
251 const ready_fiber = @atomicLoad(?*Fiber, &steal_ready_search_thread.ready_queue, .acquire) orelse continue;
252252 if (ready_fiber == Fiber.finished) continue;
253 if (@cmpxchgWeak(
254 ?*Fiber,
255 &steal_ready_search_thread.ready_queue,
256 ready_fiber,
257 null,
258 .acquire,
259 .monotonic,
260 )) |_| continue;
253261 @atomicStore(?*Fiber, &thread.ready_queue, ready_fiber.queue_next, .release);
254262 ready_fiber.queue_next = null;
255263 return ready_fiber;
......@@ -297,7 +305,7 @@ fn schedule(el: *EventLoop, thread: *Thread, ready_queue: Fiber.Queue) void {
297305 &idle_search_thread.ready_queue,
298306 null,
299307 ready_queue.head,
300 .acq_rel,
308 .release,
301309 .monotonic,
302310 )) |_| continue;
303311 getSqe(&thread.io_uring).* = .{
......@@ -1268,9 +1276,9 @@ fn conditionWait(userdata: ?*anyopaque, cond: *Io.Condition, mutex: *Io.Mutex) I
12681276 const fiber = thread.currentFiber();
12691277 const prev = @atomicRmw(?*Fiber, cond_state, .Xchg, fiber, .acquire);
12701278 assert(prev == null); // More than one wait on same Condition is illegal.
1271 mutex.unlock(io(el));
1279 mutex.unlock(el.io());
12721280 el.yield(null, .nothing);
1273 try mutex.lock(io(el));
1281 try mutex.lock(el.io());
12741282}
12751283
12761284fn conditionWake(userdata: ?*anyopaque, cond: *Io.Condition) void {