diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2024-10-23 14:46:46 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2024-10-23 16:27:39 -0700 |
| commit | 504ad56815c3deb38319ac7989dd6c50c559b780 (patch) | |
| tree | 29e01c26936f36e8f563a295110f5455f7af8f41 /src/ThreadSafeQueue.zig | |
| parent | ba71079837a071b53cab289d78e5bacb4925fd25 (diff) | |
| download | zig-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.zig | 9 |
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. |
