authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-06-11 02:25:55+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-06-12 17:51:30+01:00
logff89a98c50dbf826564657e7f98cc56194add163
tree8ea51fc317975bb3fda9e2d014458e5a7e0a0036
parent1b27369acbb2009935d49c6906363e8fa425313a
signaturelock-open Commit is signed but in an unrecognized format.

link.Queue: release safety lock before releasing mutex after stopping


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

src/link/Queue.zig+4-2
......@@ -147,8 +147,7 @@ pub fn enqueueZcu(q: *Queue, comp: *Compilation, task: ZcuTask) Allocator.Error!
147147}
148148
149149fn flushTaskQueue(tid: usize, q: *Queue, comp: *Compilation) void {
150 q.flush_safety.lock();
151 defer q.flush_safety.unlock();
150 q.flush_safety.lock(); // every `return` site should unlock this before unlocking `q.mutex`
152151
153152 if (std.debug.runtime_safety) {
154153 q.mutex.lock();
......@@ -167,6 +166,7 @@ fn flushTaskQueue(tid: usize, q: *Queue, comp: *Compilation) void {
167166 } else {
168167 // We're expecting more prelink tasks so can't move on to ZCU tasks.
169168 q.state = .finished;
169 q.flush_safety.unlock();
170170 return;
171171 }
172172 }
......@@ -200,6 +200,7 @@ fn flushTaskQueue(tid: usize, q: *Queue, comp: *Compilation) void {
200200 if (q.wip_zcu.items.len == 0) {
201201 // We've exhausted all available tasks.
202202 q.state = .finished;
203 q.flush_safety.unlock();
203204 return;
204205 }
205206 }
......@@ -215,6 +216,7 @@ fn flushTaskQueue(tid: usize, q: *Queue, comp: *Compilation) void {
215216 if (status_ptr.load(.monotonic) != .pending) break :pending;
216217 // We will stop for now, and get restarted once this MIR is ready.
217218 q.state = .{ .wait_for_mir = task.link_func.mir };
219 q.flush_safety.unlock();
218220 return;
219221 }
220222 link.doZcuTask(comp, tid, task);