diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-11-09 18:27:12 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-11-09 18:31:03 -0700 |
| commit | 008b0ec5e58fc7e31f3b989868a7d1ea4df3f41d (patch) | |
| tree | 99374a7b0f5dc0bf56fc5daff702eecb7758d4f5 /lib/std/Thread/Condition.zig | |
| parent | 65e518e8e8ab74b276c5a284caebfad4e5aa502c (diff) | |
| download | zig-008b0ec5e58fc7e31f3b989868a7d1ea4df3f41d.tar.gz zig-008b0ec5e58fc7e31f3b989868a7d1ea4df3f41d.zip | |
std.Thread.Mutex: change API to lock() and unlock()
This is a breaking change. Before, usage looked like this:
```zig
const held = mutex.acquire();
defer held.release();
```
Now it looks like this:
```zig
mutex.lock();
defer mutex.unlock();
```
The `Held` type was an idea to make mutexes slightly safer by making it
more difficult to forget to release an aquired lock. However, this
ultimately caused more problems than it solved, when any data structures
needed to store a held mutex. Simplify everything by reducing the API
down to the primitives: lock() and unlock().
Closes #8051
Closes #8246
Closes #10105
Diffstat (limited to 'lib/std/Thread/Condition.zig')
| -rw-r--r-- | lib/std/Thread/Condition.zig | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/lib/std/Thread/Condition.zig b/lib/std/Thread/Condition.zig index 658817fc08..615f68cd9b 100644 --- a/lib/std/Thread/Condition.zig +++ b/lib/std/Thread/Condition.zig @@ -145,8 +145,8 @@ pub const AtomicCondition = struct { var waiter = QueueList.Node{ .data = .{} }; { - const held = cond.queue_mutex.acquire(); - defer held.release(); + cond.queue_mutex.lock(); + defer cond.queue_mutex.unlock(); cond.queue_list.prepend(&waiter); @atomicStore(bool, &cond.pending, true, .SeqCst); @@ -162,8 +162,8 @@ pub const AtomicCondition = struct { return; const maybe_waiter = blk: { - const held = cond.queue_mutex.acquire(); - defer held.release(); + cond.queue_mutex.lock(); + defer cond.queue_mutex.unlock(); const maybe_waiter = cond.queue_list.popFirst(); @atomicStore(bool, &cond.pending, cond.queue_list.first != null, .SeqCst); @@ -181,8 +181,8 @@ pub const AtomicCondition = struct { @atomicStore(bool, &cond.pending, false, .SeqCst); var waiters = blk: { - const held = cond.queue_mutex.acquire(); - defer held.release(); + cond.queue_mutex.lock(); + defer cond.queue_mutex.unlock(); const waiters = cond.queue_list; cond.queue_list = .{}; |
