diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2023-11-23 04:55:28 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-23 04:55:28 -0500 |
| commit | 2bffd810157a8e7c0b2500a13921dd8c45694b8a (patch) | |
| tree | 2f8cfbc0403c5bd492ca68f1aa7ba6b02886ef2c /lib/std/Thread/ResetEvent.zig | |
| parent | 115ec25f2e4eed5033f34eaee8bf3477ff417ecc (diff) | |
| parent | 70931dbdea96d92feb60406c827e39e566317863 (diff) | |
| download | zig-2bffd810157a8e7c0b2500a13921dd8c45694b8a.tar.gz zig-2bffd810157a8e7c0b2500a13921dd8c45694b8a.zip | |
Merge pull request #18085 from ziglang/std-atomics
rework std.atomic
Diffstat (limited to 'lib/std/Thread/ResetEvent.zig')
| -rw-r--r-- | lib/std/Thread/ResetEvent.zig | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/lib/std/Thread/ResetEvent.zig b/lib/std/Thread/ResetEvent.zig index 42cf74fd42..cd74f337fb 100644 --- a/lib/std/Thread/ResetEvent.zig +++ b/lib/std/Thread/ResetEvent.zig @@ -9,7 +9,6 @@ const ResetEvent = @This(); const os = std.os; const assert = std.debug.assert; const testing = std.testing; -const Atomic = std.atomic.Atomic; const Futex = std.Thread.Futex; impl: Impl = .{}, @@ -89,7 +88,7 @@ const SingleThreadedImpl = struct { }; const FutexImpl = struct { - state: Atomic(u32) = Atomic(u32).init(unset), + state: std.atomic.Value(u32) = std.atomic.Value(u32).init(unset), const unset = 0; const waiting = 1; @@ -115,7 +114,7 @@ const FutexImpl = struct { // We avoid using any strict barriers until the end when we know the ResetEvent is set. var state = self.state.load(.Monotonic); if (state == unset) { - state = self.state.compareAndSwap(state, waiting, .Monotonic, .Monotonic) orelse waiting; + state = self.state.cmpxchgStrong(state, waiting, .Monotonic, .Monotonic) orelse waiting; } // Wait until the ResetEvent is set since the state is waiting. @@ -252,7 +251,7 @@ test "ResetEvent - broadcast" { const num_threads = 10; const Barrier = struct { event: ResetEvent = .{}, - counter: Atomic(usize) = Atomic(usize).init(num_threads), + counter: std.atomic.Value(usize) = std.atomic.Value(usize).init(num_threads), fn wait(self: *@This()) void { if (self.counter.fetchSub(1, .AcqRel) == 1) { |
