Skip to content

Commit ad355e0

Browse files
committed
link.Queue: release safety lock before releasing mutex after stopping
1 parent d4686be commit ad355e0

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/link/Queue.zig

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,7 @@ pub fn enqueueZcu(q: *Queue, comp: *Compilation, task: ZcuTask) Allocator.Error!
147147
}
148148

149149
fn 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);

0 commit comments

Comments
 (0)