aboutsummaryrefslogtreecommitdiff
path: root/src/ThreadSafeQueue.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2024-10-23 14:46:46 -0700
committerAndrew Kelley <andrew@ziglang.org>2024-10-23 16:27:39 -0700
commit504ad56815c3deb38319ac7989dd6c50c559b780 (patch)
tree29e01c26936f36e8f563a295110f5455f7af8f41 /src/ThreadSafeQueue.zig
parentba71079837a071b53cab289d78e5bacb4925fd25 (diff)
downloadzig-504ad56815c3deb38319ac7989dd6c50c559b780.tar.gz
zig-504ad56815c3deb38319ac7989dd6c50c559b780.zip
link.flushTaskQueue: move safety lock
The safety lock needs to happen after check()
Diffstat (limited to 'src/ThreadSafeQueue.zig')
-rw-r--r--src/ThreadSafeQueue.zig9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/ThreadSafeQueue.zig b/src/ThreadSafeQueue.zig
index 1cf6aaaa3a..74bbdc418f 100644
--- a/src/ThreadSafeQueue.zig
+++ b/src/ThreadSafeQueue.zig
@@ -52,12 +52,13 @@ pub fn ThreadSafeQueue(comptime T: type) type {
self.mutex.lock();
defer self.mutex.unlock();
try self.shared.appendSlice(gpa, items);
- const was_waiting = switch (self.state) {
+ return switch (self.state) {
.run => false,
- .wait => true,
+ .wait => {
+ self.state = .run;
+ return true;
+ },
};
- self.state = .run;
- return was_waiting;
}
/// Safe only to call exactly once when initially starting the worker.