From 70931dbdea96d92feb60406c827e39e566317863 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 22 Nov 2023 18:49:18 -0700 Subject: rework std.atomic * move std.atomic.Atomic to std.atomic.Value * fix incorrect argument order passed to testing.expectEqual * make the functions be a thin wrapper over the atomic builtins and stick to the naming conventions. * remove pointless functions loadUnchecked and storeUnchecked. Instead, name the field `raw` instead of `value` (which is redundant with the type name). * simplify the tests by not passing every possible combination. Many cases were iterating over every possible combinations but then not even using the for loop element value! * remove the redundant compile errors which are already implemented by the language itself. * remove dead x86 inline assembly. this should be implemented in the language if at all. --- lib/std/Thread/ResetEvent.zig | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'lib/std/Thread/ResetEvent.zig') 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) { -- cgit v1.2.3