authorgravatar for tristan.ross@midstall.comTristan Ross <tristan.ross@midstall.com> 2024-02-18 21:52:23-08:00
committergravatar for tristan.ross@midstall.comTristan Ross <tristan.ross@midstall.com> 2024-03-11 07:09:10-07:00
log6067d39522f939c08dd3f3ea4fb5889ff0024e72
tree0eb768171ecfb058fba72d199afc951af206f8fb
parentc260b4c753d1e5f947e0d33ce39ce173e497309f
signaturelock-open Commit is signed but in an unrecognized format.

std.builtin: make atomic order fields lowercase


45 files changed, 367 insertions(+), 367 deletions(-)

lib/build_runner.zig+6-6
......@@ -892,10 +892,10 @@ fn workerMakeOneStep(
892892 // then we return without doing the step, relying on another worker to
893893 // queue this step up again when dependencies are met.
894894 for (s.dependencies.items) |dep| {
895 switch (@atomicLoad(Step.State, &dep.state, .SeqCst)) {
895 switch (@atomicLoad(Step.State, &dep.state, .seq_cst)) {
896896 .success, .skipped => continue,
897897 .failure, .dependency_failure, .skipped_oom => {
898 @atomicStore(Step.State, &s.state, .dependency_failure, .SeqCst);
898 @atomicStore(Step.State, &s.state, .dependency_failure, .seq_cst);
899899 return;
900900 },
901901 .precheck_done, .running => {
......@@ -929,7 +929,7 @@ fn workerMakeOneStep(
929929 s.state = .running;
930930 } else {
931931 // Avoid running steps twice.
932 if (@cmpxchgStrong(Step.State, &s.state, .precheck_done, .running, .SeqCst, .SeqCst) != null) {
932 if (@cmpxchgStrong(Step.State, &s.state, .precheck_done, .running, .seq_cst, .seq_cst) != null) {
933933 // Another worker got the job.
934934 return;
935935 }
......@@ -956,13 +956,13 @@ fn workerMakeOneStep(
956956
957957 handle_result: {
958958 if (make_result) |_| {
959 @atomicStore(Step.State, &s.state, .success, .SeqCst);
959 @atomicStore(Step.State, &s.state, .success, .seq_cst);
960960 } else |err| switch (err) {
961961 error.MakeFailed => {
962 @atomicStore(Step.State, &s.state, .failure, .SeqCst);
962 @atomicStore(Step.State, &s.state, .failure, .seq_cst);
963963 break :handle_result;
964964 },
965 error.MakeSkipped => @atomicStore(Step.State, &s.state, .skipped, .SeqCst),
965 error.MakeSkipped => @atomicStore(Step.State, &s.state, .skipped, .seq_cst),
966966 }
967967
968968 // Successful completion of a step, so we queue up its dependants as well.
lib/compiler_rt/atomics.zig+9-9
......@@ -74,7 +74,7 @@ const SpinlockTable = struct {
7474 : "memory"
7575 );
7676 } else flag: {
77 break :flag @atomicRmw(@TypeOf(self.v), &self.v, .Xchg, .Locked, .Acquire);
77 break :flag @atomicRmw(@TypeOf(self.v), &self.v, .Xchg, .Locked, .acquire);
7878 };
7979
8080 switch (flag) {
......@@ -91,7 +91,7 @@ const SpinlockTable = struct {
9191 : "memory"
9292 );
9393 } else {
94 @atomicStore(@TypeOf(self.v), &self.v, .Unlocked, .Release);
94 @atomicStore(@TypeOf(self.v), &self.v, .Unlocked, .release);
9595 }
9696 }
9797 };
......@@ -172,7 +172,7 @@ inline fn atomic_load_N(comptime T: type, src: *T, model: i32) T {
172172 defer sl.release();
173173 return src.*;
174174 } else {
175 return @atomicLoad(T, src, .SeqCst);
175 return @atomicLoad(T, src, .seq_cst);
176176 }
177177}
178178
......@@ -203,7 +203,7 @@ inline fn atomic_store_N(comptime T: type, dst: *T, value: T, model: i32) void {
203203 defer sl.release();
204204 dst.* = value;
205205 } else {
206 @atomicStore(T, dst, value, .SeqCst);
206 @atomicStore(T, dst, value, .seq_cst);
207207 }
208208}
209209
......@@ -239,12 +239,12 @@ fn wideUpdate(comptime T: type, ptr: *T, val: T, update: anytype) T {
239239
240240 const mask = @as(WideAtomic, std.math.maxInt(T)) << inner_shift;
241241
242 var wide_old = @atomicLoad(WideAtomic, wide_ptr, .SeqCst);
242 var wide_old = @atomicLoad(WideAtomic, wide_ptr, .seq_cst);
243243 while (true) {
244244 const old = @as(T, @truncate((wide_old & mask) >> inner_shift));
245245 const new = update(val, old);
246246 const wide_new = wide_old & ~mask | (@as(WideAtomic, new) << inner_shift);
247 if (@cmpxchgWeak(WideAtomic, wide_ptr, wide_old, wide_new, .SeqCst, .SeqCst)) |new_wide_old| {
247 if (@cmpxchgWeak(WideAtomic, wide_ptr, wide_old, wide_new, .seq_cst, .seq_cst)) |new_wide_old| {
248248 wide_old = new_wide_old;
249249 } else {
250250 return old;
......@@ -270,7 +270,7 @@ inline fn atomic_exchange_N(comptime T: type, ptr: *T, val: T, model: i32) T {
270270 };
271271 return wideUpdate(T, ptr, val, Updater.update);
272272 } else {
273 return @atomicRmw(T, ptr, .Xchg, val, .SeqCst);
273 return @atomicRmw(T, ptr, .Xchg, val, .seq_cst);
274274 }
275275}
276276
......@@ -315,7 +315,7 @@ inline fn atomic_compare_exchange_N(
315315 expected.* = value;
316316 return 0;
317317 } else {
318 if (@cmpxchgStrong(T, ptr, expected.*, desired, .SeqCst, .SeqCst)) |old_value| {
318 if (@cmpxchgStrong(T, ptr, expected.*, desired, .seq_cst, .seq_cst)) |old_value| {
319319 expected.* = old_value;
320320 return 0;
321321 }
......@@ -373,7 +373,7 @@ inline fn fetch_op_N(comptime T: type, comptime op: std.builtin.AtomicRmwOp, ptr
373373 return wideUpdate(T, ptr, val, Updater.update);
374374 }
375375
376 return @atomicRmw(T, ptr, op, val, .SeqCst);
376 return @atomicRmw(T, ptr, op, val, .seq_cst);
377377}
378378
379379fn __atomic_fetch_add_1(ptr: *u8, val: u8, model: i32) callconv(.C) u8 {
lib/std/Progress.zig+13-13
......@@ -95,9 +95,9 @@ pub const Node = struct {
9595 /// This is the same as calling `start` and then `end` on the returned `Node`. Thread-safe.
9696 pub fn completeOne(self: *Node) void {
9797 if (self.parent) |parent| {
98 @atomicStore(?*Node, &parent.recently_updated_child, self, .Release);
98 @atomicStore(?*Node, &parent.recently_updated_child, self, .release);
9999 }
100 _ = @atomicRmw(usize, &self.unprotected_completed_items, .Add, 1, .Monotonic);
100 _ = @atomicRmw(usize, &self.unprotected_completed_items, .Add, 1, .monotonic);
101101 self.context.maybeRefresh();
102102 }
103103
......@@ -108,7 +108,7 @@ pub const Node = struct {
108108 {
109109 self.context.update_mutex.lock();
110110 defer self.context.update_mutex.unlock();
111 _ = @cmpxchgStrong(?*Node, &parent.recently_updated_child, self, null, .Monotonic, .Monotonic);
111 _ = @cmpxchgStrong(?*Node, &parent.recently_updated_child, self, null, .monotonic, .monotonic);
112112 }
113113 parent.completeOne();
114114 } else {
......@@ -122,7 +122,7 @@ pub const Node = struct {
122122 /// Tell the parent node that this node is actively being worked on. Thread-safe.
123123 pub fn activate(self: *Node) void {
124124 if (self.parent) |parent| {
125 @atomicStore(?*Node, &parent.recently_updated_child, self, .Release);
125 @atomicStore(?*Node, &parent.recently_updated_child, self, .release);
126126 self.context.maybeRefresh();
127127 }
128128 }
......@@ -134,9 +134,9 @@ pub const Node = struct {
134134 defer progress.update_mutex.unlock();
135135 self.name = name;
136136 if (self.parent) |parent| {
137 @atomicStore(?*Node, &parent.recently_updated_child, self, .Release);
137 @atomicStore(?*Node, &parent.recently_updated_child, self, .release);
138138 if (parent.parent) |grand_parent| {
139 @atomicStore(?*Node, &grand_parent.recently_updated_child, parent, .Release);
139 @atomicStore(?*Node, &grand_parent.recently_updated_child, parent, .release);
140140 }
141141 if (progress.timer) |*timer| progress.maybeRefreshWithHeldLock(timer);
142142 }
......@@ -149,9 +149,9 @@ pub const Node = struct {
149149 defer progress.update_mutex.unlock();
150150 self.unit = unit;
151151 if (self.parent) |parent| {
152 @atomicStore(?*Node, &parent.recently_updated_child, self, .Release);
152 @atomicStore(?*Node, &parent.recently_updated_child, self, .release);
153153 if (parent.parent) |grand_parent| {
154 @atomicStore(?*Node, &grand_parent.recently_updated_child, parent, .Release);
154 @atomicStore(?*Node, &grand_parent.recently_updated_child, parent, .release);
155155 }
156156 if (progress.timer) |*timer| progress.maybeRefreshWithHeldLock(timer);
157157 }
......@@ -159,12 +159,12 @@ pub const Node = struct {
159159
160160 /// Thread-safe. 0 means unknown.
161161 pub fn setEstimatedTotalItems(self: *Node, count: usize) void {
162 @atomicStore(usize, &self.unprotected_estimated_total_items, count, .Monotonic);
162 @atomicStore(usize, &self.unprotected_estimated_total_items, count, .monotonic);
163163 }
164164
165165 /// Thread-safe.
166166 pub fn setCompletedItems(self: *Node, completed_items: usize) void {
167 @atomicStore(usize, &self.unprotected_completed_items, completed_items, .Monotonic);
167 @atomicStore(usize, &self.unprotected_completed_items, completed_items, .monotonic);
168168 }
169169};
170170
......@@ -313,8 +313,8 @@ fn refreshWithHeldLock(self: *Progress) void {
313313 self.bufWrite(&end, "... ", .{});
314314 }
315315 need_ellipse = false;
316 const eti = @atomicLoad(usize, &node.unprotected_estimated_total_items, .Monotonic);
317 const completed_items = @atomicLoad(usize, &node.unprotected_completed_items, .Monotonic);
316 const eti = @atomicLoad(usize, &node.unprotected_estimated_total_items, .monotonic);
317 const completed_items = @atomicLoad(usize, &node.unprotected_completed_items, .monotonic);
318318 const current_item = completed_items + 1;
319319 if (node.name.len != 0 or eti > 0) {
320320 if (node.name.len != 0) {
......@@ -331,7 +331,7 @@ fn refreshWithHeldLock(self: *Progress) void {
331331 need_ellipse = false;
332332 }
333333 }
334 maybe_node = @atomicLoad(?*Node, &node.recently_updated_child, .Acquire);
334 maybe_node = @atomicLoad(?*Node, &node.recently_updated_child, .acquire);
335335 }
336336 if (need_ellipse) {
337337 self.bufWrite(&end, "... ", .{});
lib/std/Thread.zig+12-12
......@@ -510,7 +510,7 @@ const WindowsThreadImpl = struct {
510510
511511 fn entryFn(raw_ptr: windows.PVOID) callconv(.C) windows.DWORD {
512512 const self: *@This() = @ptrCast(@alignCast(raw_ptr));
513 defer switch (self.thread.completion.swap(.completed, .SeqCst)) {
513 defer switch (self.thread.completion.swap(.completed, .seq_cst)) {
514514 .running => {},
515515 .completed => unreachable,
516516 .detached => self.thread.free(),
......@@ -563,7 +563,7 @@ const WindowsThreadImpl = struct {
563563
564564 fn detach(self: Impl) void {
565565 windows.CloseHandle(self.thread.thread_handle);
566 switch (self.thread.completion.swap(.detached, .SeqCst)) {
566 switch (self.thread.completion.swap(.detached, .seq_cst)) {
567567 .running => {},
568568 .completed => self.thread.free(),
569569 .detached => unreachable,
......@@ -573,7 +573,7 @@ const WindowsThreadImpl = struct {
573573 fn join(self: Impl) void {
574574 windows.WaitForSingleObjectEx(self.thread.thread_handle, windows.INFINITE, false) catch unreachable;
575575 windows.CloseHandle(self.thread.thread_handle);
576 assert(self.thread.completion.load(.SeqCst) == .completed);
576 assert(self.thread.completion.load(.seq_cst) == .completed);
577577 self.thread.free();
578578 }
579579};
......@@ -780,11 +780,11 @@ const WasiThreadImpl = struct {
780780 }
781781
782782 fn getHandle(self: Impl) ThreadHandle {
783 return self.thread.tid.load(.SeqCst);
783 return self.thread.tid.load(.seq_cst);
784784 }
785785
786786 fn detach(self: Impl) void {
787 switch (self.thread.state.swap(.detached, .SeqCst)) {
787 switch (self.thread.state.swap(.detached, .seq_cst)) {
788788 .running => {},
789789 .completed => self.join(),
790790 .detached => unreachable,
......@@ -801,7 +801,7 @@ const WasiThreadImpl = struct {
801801
802802 var spin: u8 = 10;
803803 while (true) {
804 const tid = self.thread.tid.load(.SeqCst);
804 const tid = self.thread.tid.load(.seq_cst);
805805 if (tid == 0) {
806806 break;
807807 }
......@@ -901,7 +901,7 @@ const WasiThreadImpl = struct {
901901 if (tid < 0) {
902902 return error.SystemResources;
903903 }
904 instance.thread.tid.store(tid, .SeqCst);
904 instance.thread.tid.store(tid, .seq_cst);
905905
906906 return .{ .thread = &instance.thread };
907907 }
......@@ -914,12 +914,12 @@ const WasiThreadImpl = struct {
914914 }
915915 __set_stack_pointer(arg.thread.memory.ptr + arg.stack_offset);
916916 __wasm_init_tls(arg.thread.memory.ptr + arg.tls_offset);
917 @atomicStore(u32, &WasiThreadImpl.tls_thread_id, @intCast(tid), .SeqCst);
917 @atomicStore(u32, &WasiThreadImpl.tls_thread_id, @intCast(tid), .seq_cst);
918918
919919 // Finished bootstrapping, call user's procedure.
920920 arg.call_back(arg.raw_ptr);
921921
922 switch (arg.thread.state.swap(.completed, .SeqCst)) {
922 switch (arg.thread.state.swap(.completed, .seq_cst)) {
923923 .running => {
924924 // reset the Thread ID
925925 asm volatile (
......@@ -1191,7 +1191,7 @@ const LinuxThreadImpl = struct {
11911191
11921192 fn entryFn(raw_arg: usize) callconv(.C) u8 {
11931193 const self = @as(*@This(), @ptrFromInt(raw_arg));
1194 defer switch (self.thread.completion.swap(.completed, .SeqCst)) {
1194 defer switch (self.thread.completion.swap(.completed, .seq_cst)) {
11951195 .running => {},
11961196 .completed => unreachable,
11971197 .detached => self.thread.freeAndExit(),
......@@ -1311,7 +1311,7 @@ const LinuxThreadImpl = struct {
13111311 }
13121312
13131313 fn detach(self: Impl) void {
1314 switch (self.thread.completion.swap(.detached, .SeqCst)) {
1314 switch (self.thread.completion.swap(.detached, .seq_cst)) {
13151315 .running => {},
13161316 .completed => self.join(),
13171317 .detached => unreachable,
......@@ -1323,7 +1323,7 @@ const LinuxThreadImpl = struct {
13231323
13241324 var spin: u8 = 10;
13251325 while (true) {
1326 const tid = self.thread.child_tid.load(.SeqCst);
1326 const tid = self.thread.child_tid.load(.seq_cst);
13271327 if (tid == 0) {
13281328 break;
13291329 }
lib/std/Thread/Condition.zig+12-12
......@@ -163,7 +163,7 @@ const WindowsImpl = struct {
163163
164164 if (comptime builtin.mode == .Debug) {
165165 // The internal state of the DebugMutex needs to be handled here as well.
166 mutex.impl.locking_thread.store(0, .Unordered);
166 mutex.impl.locking_thread.store(0, .unordered);
167167 }
168168 const rc = os.windows.kernel32.SleepConditionVariableSRW(
169169 &self.condition,
......@@ -173,7 +173,7 @@ const WindowsImpl = struct {
173173 );
174174 if (comptime builtin.mode == .Debug) {
175175 // The internal state of the DebugMutex needs to be handled here as well.
176 mutex.impl.locking_thread.store(std.Thread.getCurrentId(), .Unordered);
176 mutex.impl.locking_thread.store(std.Thread.getCurrentId(), .unordered);
177177 }
178178
179179 // Return error.Timeout if we know the timeout elapsed correctly.
......@@ -212,8 +212,8 @@ const FutexImpl = struct {
212212 // - T1: s & signals == 0 -> FUTEX_WAIT(&epoch, e) (missed the state update + the epoch change)
213213 //
214214 // Acquire barrier to ensure the epoch load happens before the state load.
215 var epoch = self.epoch.load(.Acquire);
216 var state = self.state.fetchAdd(one_waiter, .Monotonic);
215 var epoch = self.epoch.load(.acquire);
216 var state = self.state.fetchAdd(one_waiter, .monotonic);
217217 assert(state & waiter_mask != waiter_mask);
218218 state += one_waiter;
219219
......@@ -231,30 +231,30 @@ const FutexImpl = struct {
231231 // Acquire barrier ensures code before the wake() which added the signal happens before we decrement it and return.
232232 while (state & signal_mask != 0) {
233233 const new_state = state - one_waiter - one_signal;
234 state = self.state.cmpxchgWeak(state, new_state, .Acquire, .Monotonic) orelse return;
234 state = self.state.cmpxchgWeak(state, new_state, .acquire, .monotonic) orelse return;
235235 }
236236
237237 // Remove the waiter we added and officially return timed out.
238238 const new_state = state - one_waiter;
239 state = self.state.cmpxchgWeak(state, new_state, .Monotonic, .Monotonic) orelse return err;
239 state = self.state.cmpxchgWeak(state, new_state, .monotonic, .monotonic) orelse return err;
240240 }
241241 },
242242 };
243243
244 epoch = self.epoch.load(.Acquire);
245 state = self.state.load(.Monotonic);
244 epoch = self.epoch.load(.acquire);
245 state = self.state.load(.monotonic);
246246
247247 // Try to wake up by consuming a signal and decremented the waiter we added previously.
248248 // Acquire barrier ensures code before the wake() which added the signal happens before we decrement it and return.
249249 while (state & signal_mask != 0) {
250250 const new_state = state - one_waiter - one_signal;
251 state = self.state.cmpxchgWeak(state, new_state, .Acquire, .Monotonic) orelse return;
251 state = self.state.cmpxchgWeak(state, new_state, .acquire, .monotonic) orelse return;
252252 }
253253 }
254254 }
255255
256256 fn wake(self: *Impl, comptime notify: Notify) void {
257 var state = self.state.load(.Monotonic);
257 var state = self.state.load(.monotonic);
258258 while (true) {
259259 const waiters = (state & waiter_mask) / one_waiter;
260260 const signals = (state & signal_mask) / one_signal;
......@@ -275,7 +275,7 @@ const FutexImpl = struct {
275275 // Reserve the amount of waiters to wake by incrementing the signals count.
276276 // Release barrier ensures code before the wake() happens before the signal it posted and consumed by the wait() threads.
277277 const new_state = state + (one_signal * to_wake);
278 state = self.state.cmpxchgWeak(state, new_state, .Release, .Monotonic) orelse {
278 state = self.state.cmpxchgWeak(state, new_state, .release, .monotonic) orelse {
279279 // Wake up the waiting threads we reserved above by changing the epoch value.
280280 // NOTE: a waiting thread could miss a wake up if *exactly* ((1<<32)-1) wake()s happen between it observing the epoch and sleeping on it.
281281 // This is very unlikely due to how many precise amount of Futex.wake() calls that would be between the waiting thread's potential preemption.
......@@ -288,7 +288,7 @@ const FutexImpl = struct {
288288 // - T1: s = LOAD(&state)
289289 // - T2: UPDATE(&state, signal) + FUTEX_WAKE(&epoch)
290290 // - T1: s & signals == 0 -> FUTEX_WAIT(&epoch, e) (missed both epoch change and state change)
291 _ = self.epoch.fetchAdd(1, .Release);
291 _ = self.epoch.fetchAdd(1, .release);
292292 Futex.wake(&self.epoch, to_wake);
293293 return;
294294 };
lib/std/Thread/Futex.zig+15-15
......@@ -40,7 +40,7 @@ pub fn timedWait(ptr: *const atomic.Value(u32), expect: u32, timeout_ns: u64) er
4040
4141 // Avoid calling into the OS for no-op timeouts.
4242 if (timeout_ns == 0) {
43 if (ptr.load(.SeqCst) != expect) return;
43 if (ptr.load(.seq_cst) != expect) return;
4444 return error.Timeout;
4545 }
4646
......@@ -783,16 +783,16 @@ const PosixImpl = struct {
783783 // - T1: bumps pending waiters (was reordered after the ptr == expect check)
784784 // - T1: goes to sleep and misses both the ptr change and T2's wake up
785785 //
786 // SeqCst as Acquire barrier to ensure the announcement happens before the ptr check below.
787 // SeqCst as shared modification order to form a happens-before edge with the fence(.SeqCst)+load() in wake().
788 var pending = bucket.pending.fetchAdd(1, .SeqCst);
786 // seq_cst as Acquire barrier to ensure the announcement happens before the ptr check below.
787 // seq_cst as shared modification order to form a happens-before edge with the fence(.seq_cst)+load() in wake().
788 var pending = bucket.pending.fetchAdd(1, .seq_cst);
789789 assert(pending < std.math.maxInt(usize));
790790
791791 // If the wait gets cancelled, remove the pending count we previously added.
792792 // This is done outside the mutex lock to keep the critical section short in case of contention.
793793 var cancelled = false;
794794 defer if (cancelled) {
795 pending = bucket.pending.fetchSub(1, .Monotonic);
795 pending = bucket.pending.fetchSub(1, .monotonic);
796796 assert(pending > 0);
797797 };
798798
......@@ -850,11 +850,11 @@ const PosixImpl = struct {
850850 // but the RMW operation unconditionally marks the cache-line as modified for others causing unnecessary fetching/contention.
851851 //
852852 // Instead we opt to do a full-fence + load instead which avoids taking ownership of the cache-line.
853 // fence(SeqCst) effectively converts the ptr update to SeqCst and the pending load to SeqCst: creating a Store-Load barrier.
853 // fence(seq_cst) effectively converts the ptr update to seq_cst and the pending load to seq_cst: creating a Store-Load barrier.
854854 //
855 // The pending count increment in wait() must also now use SeqCst for the update + this pending load
856 // to be in the same modification order as our load isn't using Release/Acquire to guarantee it.
857 bucket.pending.fence(.SeqCst);
855 // The pending count increment in wait() must also now use seq_cst for the update + this pending load
856 // to be in the same modification order as our load isn't using release/acquire to guarantee it.
857 bucket.pending.fence(.seq_cst);
858858 if (bucket.pending.load(.Monotonic) == 0) {
859859 return;
860860 }
......@@ -912,7 +912,7 @@ test "signaling" {
912912 current: u32 = 0,
913913
914914 fn hit(self: *@This()) void {
915 _ = self.value.fetchAdd(1, .Release);
915 _ = self.value.fetchAdd(1, .release);
916916 Futex.wake(&self.value, 1);
917917 }
918918
......@@ -921,7 +921,7 @@ test "signaling" {
921921 // Wait for the value to change from hit()
922922 var new_value: u32 = undefined;
923923 while (true) {
924 new_value = self.value.load(.Acquire);
924 new_value = self.value.load(.acquire);
925925 if (new_value != self.current) break;
926926 Futex.wait(&self.value, self.current);
927927 }
......@@ -968,7 +968,7 @@ test "broadcasting" {
968968 fn wait(self: *@This()) !void {
969969 // Decrement the counter.
970970 // Release ensures stuff before this barrier.wait() happens before the last one.
971 const count = self.count.fetchSub(1, .Release);
971 const count = self.count.fetchSub(1, .release);
972972 try testing.expect(count <= num_threads);
973973 try testing.expect(count > 0);
974974
......@@ -976,15 +976,15 @@ test "broadcasting" {
976976 // Acquire for the last counter ensures stuff before previous barrier.wait()s happened before it.
977977 // Release on futex update ensures stuff before all barrier.wait()'s happens before they all return.
978978 if (count - 1 == 0) {
979 _ = self.count.load(.Acquire); // TODO: could be fence(Acquire) if not for TSAN
980 self.futex.store(1, .Release);
979 _ = self.count.load(.acquire); // TODO: could be fence(acquire) if not for TSAN
980 self.futex.store(1, .release);
981981 Futex.wake(&self.futex, num_threads - 1);
982982 return;
983983 }
984984
985985 // Other threads wait until last counter wakes them up.
986986 // Acquire on futex synchronizes with last barrier count to ensure stuff before all barrier.wait()'s happen before us.
987 while (self.futex.load(.Acquire) == 0) {
987 while (self.futex.load(.acquire) == 0) {
988988 Futex.wait(&self.futex, 0);
989989 }
990990 }
lib/std/Thread/Mutex.zig+10-10
......@@ -72,23 +72,23 @@ const DebugImpl = struct {
7272 inline fn tryLock(self: *@This()) bool {
7373 const locking = self.impl.tryLock();
7474 if (locking) {
75 self.locking_thread.store(Thread.getCurrentId(), .Unordered);
75 self.locking_thread.store(Thread.getCurrentId(), .unordered);
7676 }
7777 return locking;
7878 }
7979
8080 inline fn lock(self: *@This()) void {
8181 const current_id = Thread.getCurrentId();
82 if (self.locking_thread.load(.Unordered) == current_id and current_id != 0) {
82 if (self.locking_thread.load(.unordered) == current_id and current_id != 0) {
8383 @panic("Deadlock detected");
8484 }
8585 self.impl.lock();
86 self.locking_thread.store(current_id, .Unordered);
86 self.locking_thread.store(current_id, .unordered);
8787 }
8888
8989 inline fn unlock(self: *@This()) void {
90 assert(self.locking_thread.load(.Unordered) == Thread.getCurrentId());
91 self.locking_thread.store(0, .Unordered);
90 assert(self.locking_thread.load(.unordered) == Thread.getCurrentId());
91 self.locking_thread.store(0, .unordered);
9292 self.impl.unlock();
9393 }
9494};
......@@ -167,12 +167,12 @@ const FutexImpl = struct {
167167 // - `lock bts` is smaller instruction-wise which makes it better for inlining
168168 if (comptime builtin.target.cpu.arch.isX86()) {
169169 const locked_bit = @ctz(locked);
170 return self.state.bitSet(locked_bit, .Acquire) == 0;
170 return self.state.bitSet(locked_bit, .acquire) == 0;
171171 }
172172
173173 // Acquire barrier ensures grabbing the lock happens before the critical section
174174 // and that the previous lock holder's critical section happens before we grab the lock.
175 return self.state.cmpxchgWeak(unlocked, locked, .Acquire, .Monotonic) == null;
175 return self.state.cmpxchgWeak(unlocked, locked, .acquire, .monotonic) == null;
176176 }
177177
178178 fn lockSlow(self: *@This()) void {
......@@ -180,7 +180,7 @@ const FutexImpl = struct {
180180
181181 // Avoid doing an atomic swap below if we already know the state is contended.
182182 // An atomic swap unconditionally stores which marks the cache-line as modified unnecessarily.
183 if (self.state.load(.Monotonic) == contended) {
183 if (self.state.load(.monotonic) == contended) {
184184 Futex.wait(&self.state, contended);
185185 }
186186
......@@ -193,7 +193,7 @@ const FutexImpl = struct {
193193 //
194194 // Acquire barrier ensures grabbing the lock happens before the critical section
195195 // and that the previous lock holder's critical section happens before we grab the lock.
196 while (self.state.swap(contended, .Acquire) != unlocked) {
196 while (self.state.swap(contended, .acquire) != unlocked) {
197197 Futex.wait(&self.state, contended);
198198 }
199199 }
......@@ -206,7 +206,7 @@ const FutexImpl = struct {
206206 //
207207 // Release barrier ensures the critical section happens before we let go of the lock
208208 // and that our critical section happens before the next lock holder grabs the lock.
209 const state = self.state.swap(unlocked, .Release);
209 const state = self.state.swap(unlocked, .release);
210210 assert(state != unlocked);
211211
212212 if (state == contended) {
lib/std/Thread/ResetEvent.zig+9-9
......@@ -96,7 +96,7 @@ const FutexImpl = struct {
9696
9797 fn isSet(self: *const Impl) bool {
9898 // Acquire barrier ensures memory accesses before set() happen before we return true.
99 return self.state.load(.Acquire) == is_set;
99 return self.state.load(.acquire) == is_set;
100100 }
101101
102102 fn wait(self: *Impl, timeout: ?u64) error{Timeout}!void {
......@@ -112,9 +112,9 @@ const FutexImpl = struct {
112112 // Try to set the state from `unset` to `waiting` to indicate
113113 // to the set() thread that others are blocked on the ResetEvent.
114114 // We avoid using any strict barriers until the end when we know the ResetEvent is set.
115 var state = self.state.load(.Monotonic);
115 var state = self.state.load(.monotonic);
116116 if (state == unset) {
117 state = self.state.cmpxchgStrong(state, waiting, .Monotonic, .Monotonic) orelse waiting;
117 state = self.state.cmpxchgStrong(state, waiting, .monotonic, .monotonic) orelse waiting;
118118 }
119119
120120 // Wait until the ResetEvent is set since the state is waiting.
......@@ -124,7 +124,7 @@ const FutexImpl = struct {
124124 const wait_result = futex_deadline.wait(&self.state, waiting);
125125
126126 // Check if the ResetEvent was set before possibly reporting error.Timeout below.
127 state = self.state.load(.Monotonic);
127 state = self.state.load(.monotonic);
128128 if (state != waiting) {
129129 break;
130130 }
......@@ -135,25 +135,25 @@ const FutexImpl = struct {
135135
136136 // Acquire barrier ensures memory accesses before set() happen before we return.
137137 assert(state == is_set);
138 self.state.fence(.Acquire);
138 self.state.fence(.acquire);
139139 }
140140
141141 fn set(self: *Impl) void {
142142 // Quick check if the ResetEvent is already set before doing the atomic swap below.
143143 // set() could be getting called quite often and multiple threads calling swap() increases contention unnecessarily.
144 if (self.state.load(.Monotonic) == is_set) {
144 if (self.state.load(.monotonic) == is_set) {
145145 return;
146146 }
147147
148148 // Mark the ResetEvent as set and unblock all waiters waiting on it if any.
149149 // Release barrier ensures memory accesses before set() happen before the ResetEvent is observed to be "set".
150 if (self.state.swap(is_set, .Release) == waiting) {
150 if (self.state.swap(is_set, .release) == waiting) {
151151 Futex.wake(&self.state, std.math.maxInt(u32));
152152 }
153153 }
154154
155155 fn reset(self: *Impl) void {
156 self.state.store(unset, .Monotonic);
156 self.state.store(unset, .monotonic);
157157 }
158158};
159159
......@@ -254,7 +254,7 @@ test "broadcast" {
254254 counter: std.atomic.Value(usize) = std.atomic.Value(usize).init(num_threads),
255255
256256 fn wait(self: *@This()) void {
257 if (self.counter.fetchSub(1, .AcqRel) == 1) {
257 if (self.counter.fetchSub(1, .acq_rel) == 1) {
258258 self.event.set();
259259 }
260260 }
lib/std/Thread/RwLock.zig+16-16
......@@ -179,9 +179,9 @@ pub const DefaultRwLock = struct {
179179
180180 pub fn tryLock(rwl: *DefaultRwLock) bool {
181181 if (rwl.mutex.tryLock()) {
182 const state = @atomicLoad(usize, &rwl.state, .SeqCst);
182 const state = @atomicLoad(usize, &rwl.state, .seq_cst);
183183 if (state & READER_MASK == 0) {
184 _ = @atomicRmw(usize, &rwl.state, .Or, IS_WRITING, .SeqCst);
184 _ = @atomicRmw(usize, &rwl.state, .Or, IS_WRITING, .seq_cst);
185185 return true;
186186 }
187187
......@@ -192,34 +192,34 @@ pub const DefaultRwLock = struct {
192192 }
193193
194194 pub fn lock(rwl: *DefaultRwLock) void {
195 _ = @atomicRmw(usize, &rwl.state, .Add, WRITER, .SeqCst);
195 _ = @atomicRmw(usize, &rwl.state, .Add, WRITER, .seq_cst);
196196 rwl.mutex.lock();
197197
198 const state = @atomicRmw(usize, &rwl.state, .Add, IS_WRITING -% WRITER, .SeqCst);
198 const state = @atomicRmw(usize, &rwl.state, .Add, IS_WRITING -% WRITER, .seq_cst);
199199 if (state & READER_MASK != 0)
200200 rwl.semaphore.wait();
201201 }
202202
203203 pub fn unlock(rwl: *DefaultRwLock) void {
204 _ = @atomicRmw(usize, &rwl.state, .And, ~IS_WRITING, .SeqCst);
204 _ = @atomicRmw(usize, &rwl.state, .And, ~IS_WRITING, .seq_cst);
205205 rwl.mutex.unlock();
206206 }
207207
208208 pub fn tryLockShared(rwl: *DefaultRwLock) bool {
209 const state = @atomicLoad(usize, &rwl.state, .SeqCst);
209 const state = @atomicLoad(usize, &rwl.state, .seq_cst);
210210 if (state & (IS_WRITING | WRITER_MASK) == 0) {
211211 _ = @cmpxchgStrong(
212212 usize,
213213 &rwl.state,
214214 state,
215215 state + READER,
216 .SeqCst,
217 .SeqCst,
216 .seq_cst,
217 .seq_cst,
218218 ) orelse return true;
219219 }
220220
221221 if (rwl.mutex.tryLock()) {
222 _ = @atomicRmw(usize, &rwl.state, .Add, READER, .SeqCst);
222 _ = @atomicRmw(usize, &rwl.state, .Add, READER, .seq_cst);
223223 rwl.mutex.unlock();
224224 return true;
225225 }
......@@ -228,25 +228,25 @@ pub const DefaultRwLock = struct {
228228 }
229229
230230 pub fn lockShared(rwl: *DefaultRwLock) void {
231 var state = @atomicLoad(usize, &rwl.state, .SeqCst);
231 var state = @atomicLoad(usize, &rwl.state, .seq_cst);
232232 while (state & (IS_WRITING | WRITER_MASK) == 0) {
233233 state = @cmpxchgWeak(
234234 usize,
235235 &rwl.state,
236236 state,
237237 state + READER,
238 .SeqCst,
239 .SeqCst,
238 .seq_cst,
239 .seq_cst,
240240 ) orelse return;
241241 }
242242
243243 rwl.mutex.lock();
244 _ = @atomicRmw(usize, &rwl.state, .Add, READER, .SeqCst);
244 _ = @atomicRmw(usize, &rwl.state, .Add, READER, .seq_cst);
245245 rwl.mutex.unlock();
246246 }
247247
248248 pub fn unlockShared(rwl: *DefaultRwLock) void {
249 const state = @atomicRmw(usize, &rwl.state, .Sub, READER, .SeqCst);
249 const state = @atomicRmw(usize, &rwl.state, .Sub, READER, .seq_cst);
250250
251251 if ((state & READER_MASK == READER) and (state & IS_WRITING != 0))
252252 rwl.semaphore.post();
......@@ -318,12 +318,12 @@ test "concurrent access" {
318318 self.rwl.lockShared();
319319 defer self.rwl.unlockShared();
320320
321 if (self.writes >= num_writes or self.reads.load(.Unordered) >= num_reads)
321 if (self.writes >= num_writes or self.reads.load(.unordered) >= num_reads)
322322 break;
323323
324324 try self.check();
325325
326 _ = self.reads.fetchAdd(1, .Monotonic);
326 _ = self.reads.fetchAdd(1, .monotonic);
327327 }
328328 }
329329
lib/std/Thread/WaitGroup.zig+6-6
......@@ -10,22 +10,22 @@ state: std.atomic.Value(usize) = std.atomic.Value(usize).init(0),
1010event: std.Thread.ResetEvent = .{},
1111
1212pub fn start(self: *WaitGroup) void {
13 const state = self.state.fetchAdd(one_pending, .Monotonic);
13 const state = self.state.fetchAdd(one_pending, .monotonic);
1414 assert((state / one_pending) < (std.math.maxInt(usize) / one_pending));
1515}
1616
1717pub fn finish(self: *WaitGroup) void {
18 const state = self.state.fetchSub(one_pending, .Release);
18 const state = self.state.fetchSub(one_pending, .release);
1919 assert((state / one_pending) > 0);
2020
2121 if (state == (one_pending | is_waiting)) {
22 self.state.fence(.Acquire);
22 self.state.fence(.acquire);
2323 self.event.set();
2424 }
2525}
2626
2727pub fn wait(self: *WaitGroup) void {
28 const state = self.state.fetchAdd(is_waiting, .Acquire);
28 const state = self.state.fetchAdd(is_waiting, .acquire);
2929 assert(state & is_waiting == 0);
3030
3131 if ((state / one_pending) > 0) {
......@@ -34,12 +34,12 @@ pub fn wait(self: *WaitGroup) void {
3434}
3535
3636pub fn reset(self: *WaitGroup) void {
37 self.state.store(0, .Monotonic);
37 self.state.store(0, .monotonic);
3838 self.event.reset();
3939}
4040
4141pub fn isDone(wg: *WaitGroup) bool {
42 const state = wg.state.load(.Acquire);
42 const state = wg.state.load(.acquire);
4343 assert(state & is_waiting == 0);
4444
4545 return (state / one_pending) == 0;
lib/std/atomic.zig+82-82
......@@ -23,10 +23,10 @@ pub fn Value(comptime T: type) type {
2323
2424 const addr: *anyopaque = self;
2525 return switch (order) {
26 .Unordered, .Monotonic => @compileError(@tagName(order) ++ " only applies to atomic loads and stores"),
27 .Acquire => tsan.__tsan_acquire(addr),
28 .Release => tsan.__tsan_release(addr),
29 .AcqRel, .SeqCst => {
26 .unordered, .monotonic => @compileError(@tagName(order) ++ " only applies to atomic loads and stores"),
27 .acquire => tsan.__tsan_acquire(addr),
28 .release => tsan.__tsan_release(addr),
29 .acq_rel, .seq_cst => {
3030 tsan.__tsan_acquire(addr);
3131 tsan.__tsan_release(addr);
3232 },
......@@ -149,20 +149,20 @@ test Value {
149149
150150 fn ref(rc: *RefCount) void {
151151 // No ordering necessary; just updating a counter.
152 _ = rc.count.fetchAdd(1, .Monotonic);
152 _ = rc.count.fetchAdd(1, .monotonic);
153153 }
154154
155155 fn unref(rc: *RefCount) void {
156156 // Release ensures code before unref() happens-before the
157157 // count is decremented as dropFn could be called by then.
158 if (rc.count.fetchSub(1, .Release) == 1) {
159 // Acquire ensures count decrement and code before
158 if (rc.count.fetchSub(1, .release) == 1) {
159 // acquire ensures count decrement and code before
160160 // previous unrefs()s happens-before we call dropFn
161161 // below.
162162 // Another alternative is to use .AcqRel on the
163163 // fetchSub count decrement but it's extra barrier in
164164 // possibly hot path.
165 rc.count.fence(.Acquire);
165 rc.count.fence(.acquire);
166166 (rc.dropFn)(rc);
167167 }
168168 }
......@@ -182,118 +182,118 @@ test Value {
182182
183183test "Value.swap" {
184184 var x = Value(usize).init(5);
185 try testing.expectEqual(@as(usize, 5), x.swap(10, .SeqCst));
186 try testing.expectEqual(@as(usize, 10), x.load(.SeqCst));
185 try testing.expectEqual(@as(usize, 5), x.swap(10, .seq_cst));
186 try testing.expectEqual(@as(usize, 10), x.load(.seq_cst));
187187
188188 const E = enum(usize) { a, b, c };
189189 var y = Value(E).init(.c);
190 try testing.expectEqual(E.c, y.swap(.a, .SeqCst));
191 try testing.expectEqual(E.a, y.load(.SeqCst));
190 try testing.expectEqual(E.c, y.swap(.a, .seq_cst));
191 try testing.expectEqual(E.a, y.load(.seq_cst));
192192
193193 var z = Value(f32).init(5.0);
194 try testing.expectEqual(@as(f32, 5.0), z.swap(10.0, .SeqCst));
195 try testing.expectEqual(@as(f32, 10.0), z.load(.SeqCst));
194 try testing.expectEqual(@as(f32, 5.0), z.swap(10.0, .seq_cst));
195 try testing.expectEqual(@as(f32, 10.0), z.load(.seq_cst));
196196
197197 var a = Value(bool).init(false);
198 try testing.expectEqual(false, a.swap(true, .SeqCst));
199 try testing.expectEqual(true, a.load(.SeqCst));
198 try testing.expectEqual(false, a.swap(true, .seq_cst));
199 try testing.expectEqual(true, a.load(.seq_cst));
200200
201201 var b = Value(?*u8).init(null);
202 try testing.expectEqual(@as(?*u8, null), b.swap(@as(?*u8, @ptrFromInt(@alignOf(u8))), .SeqCst));
203 try testing.expectEqual(@as(?*u8, @ptrFromInt(@alignOf(u8))), b.load(.SeqCst));
202 try testing.expectEqual(@as(?*u8, null), b.swap(@as(?*u8, @ptrFromInt(@alignOf(u8))), .seq_cst));
203 try testing.expectEqual(@as(?*u8, @ptrFromInt(@alignOf(u8))), b.load(.seq_cst));
204204}
205205
206206test "Value.store" {
207207 var x = Value(usize).init(5);
208 x.store(10, .SeqCst);
209 try testing.expectEqual(@as(usize, 10), x.load(.SeqCst));
208 x.store(10, .seq_cst);
209 try testing.expectEqual(@as(usize, 10), x.load(.seq_cst));
210210}
211211
212212test "Value.cmpxchgWeak" {
213213 var x = Value(usize).init(0);
214214
215 try testing.expectEqual(@as(?usize, 0), x.cmpxchgWeak(1, 0, .SeqCst, .SeqCst));
216 try testing.expectEqual(@as(usize, 0), x.load(.SeqCst));
215 try testing.expectEqual(@as(?usize, 0), x.cmpxchgWeak(1, 0, .seq_cst, .seq_cst));
216 try testing.expectEqual(@as(usize, 0), x.load(.seq_cst));
217217
218 while (x.cmpxchgWeak(0, 1, .SeqCst, .SeqCst)) |_| {}
219 try testing.expectEqual(@as(usize, 1), x.load(.SeqCst));
218 while (x.cmpxchgWeak(0, 1, .seq_cst, .seq_cst)) |_| {}
219 try testing.expectEqual(@as(usize, 1), x.load(.seq_cst));
220220
221 while (x.cmpxchgWeak(1, 0, .SeqCst, .SeqCst)) |_| {}
222 try testing.expectEqual(@as(usize, 0), x.load(.SeqCst));
221 while (x.cmpxchgWeak(1, 0, .seq_cst, .seq_cst)) |_| {}
222 try testing.expectEqual(@as(usize, 0), x.load(.seq_cst));
223223}
224224
225225test "Value.cmpxchgStrong" {
226226 var x = Value(usize).init(0);
227 try testing.expectEqual(@as(?usize, 0), x.cmpxchgStrong(1, 0, .SeqCst, .SeqCst));
228 try testing.expectEqual(@as(usize, 0), x.load(.SeqCst));
229 try testing.expectEqual(@as(?usize, null), x.cmpxchgStrong(0, 1, .SeqCst, .SeqCst));
230 try testing.expectEqual(@as(usize, 1), x.load(.SeqCst));
231 try testing.expectEqual(@as(?usize, null), x.cmpxchgStrong(1, 0, .SeqCst, .SeqCst));
232 try testing.expectEqual(@as(usize, 0), x.load(.SeqCst));
227 try testing.expectEqual(@as(?usize, 0), x.cmpxchgStrong(1, 0, .seq_cst, .seq_cst));
228 try testing.expectEqual(@as(usize, 0), x.load(.seq_cst));
229 try testing.expectEqual(@as(?usize, null), x.cmpxchgStrong(0, 1, .seq_cst, .seq_cst));
230 try testing.expectEqual(@as(usize, 1), x.load(.seq_cst));
231 try testing.expectEqual(@as(?usize, null), x.cmpxchgStrong(1, 0, .seq_cst, .seq_cst));
232 try testing.expectEqual(@as(usize, 0), x.load(.seq_cst));
233233}
234234
235235test "Value.fetchAdd" {
236236 var x = Value(usize).init(5);
237 try testing.expectEqual(@as(usize, 5), x.fetchAdd(5, .SeqCst));
238 try testing.expectEqual(@as(usize, 10), x.load(.SeqCst));
239 try testing.expectEqual(@as(usize, 10), x.fetchAdd(std.math.maxInt(usize), .SeqCst));
240 try testing.expectEqual(@as(usize, 9), x.load(.SeqCst));
237 try testing.expectEqual(@as(usize, 5), x.fetchAdd(5, .seq_cst));
238 try testing.expectEqual(@as(usize, 10), x.load(.seq_cst));
239 try testing.expectEqual(@as(usize, 10), x.fetchAdd(std.math.maxInt(usize), .seq_cst));
240 try testing.expectEqual(@as(usize, 9), x.load(.seq_cst));
241241}
242242
243243test "Value.fetchSub" {
244244 var x = Value(usize).init(5);
245 try testing.expectEqual(@as(usize, 5), x.fetchSub(5, .SeqCst));
246 try testing.expectEqual(@as(usize, 0), x.load(.SeqCst));
247 try testing.expectEqual(@as(usize, 0), x.fetchSub(1, .SeqCst));
248 try testing.expectEqual(@as(usize, std.math.maxInt(usize)), x.load(.SeqCst));
245 try testing.expectEqual(@as(usize, 5), x.fetchSub(5, .seq_cst));
246 try testing.expectEqual(@as(usize, 0), x.load(.seq_cst));
247 try testing.expectEqual(@as(usize, 0), x.fetchSub(1, .seq_cst));
248 try testing.expectEqual(@as(usize, std.math.maxInt(usize)), x.load(.seq_cst));
249249}
250250
251251test "Value.fetchMin" {
252252 var x = Value(usize).init(5);
253 try testing.expectEqual(@as(usize, 5), x.fetchMin(0, .SeqCst));
254 try testing.expectEqual(@as(usize, 0), x.load(.SeqCst));
255 try testing.expectEqual(@as(usize, 0), x.fetchMin(10, .SeqCst));
256 try testing.expectEqual(@as(usize, 0), x.load(.SeqCst));
253 try testing.expectEqual(@as(usize, 5), x.fetchMin(0, .seq_cst));
254 try testing.expectEqual(@as(usize, 0), x.load(.seq_cst));
255 try testing.expectEqual(@as(usize, 0), x.fetchMin(10, .seq_cst));
256 try testing.expectEqual(@as(usize, 0), x.load(.seq_cst));
257257}
258258
259259test "Value.fetchMax" {
260260 var x = Value(usize).init(5);
261 try testing.expectEqual(@as(usize, 5), x.fetchMax(10, .SeqCst));
262 try testing.expectEqual(@as(usize, 10), x.load(.SeqCst));
263 try testing.expectEqual(@as(usize, 10), x.fetchMax(5, .SeqCst));
264 try testing.expectEqual(@as(usize, 10), x.load(.SeqCst));
261 try testing.expectEqual(@as(usize, 5), x.fetchMax(10, .seq_cst));
262 try testing.expectEqual(@as(usize, 10), x.load(.seq_cst));
263 try testing.expectEqual(@as(usize, 10), x.fetchMax(5, .seq_cst));
264 try testing.expectEqual(@as(usize, 10), x.load(.seq_cst));
265265}
266266
267267test "Value.fetchAnd" {
268268 var x = Value(usize).init(0b11);
269 try testing.expectEqual(@as(usize, 0b11), x.fetchAnd(0b10, .SeqCst));
270 try testing.expectEqual(@as(usize, 0b10), x.load(.SeqCst));
271 try testing.expectEqual(@as(usize, 0b10), x.fetchAnd(0b00, .SeqCst));
272 try testing.expectEqual(@as(usize, 0b00), x.load(.SeqCst));
269 try testing.expectEqual(@as(usize, 0b11), x.fetchAnd(0b10, .seq_cst));
270 try testing.expectEqual(@as(usize, 0b10), x.load(.seq_cst));
271 try testing.expectEqual(@as(usize, 0b10), x.fetchAnd(0b00, .seq_cst));
272 try testing.expectEqual(@as(usize, 0b00), x.load(.seq_cst));
273273}
274274
275275test "Value.fetchNand" {
276276 var x = Value(usize).init(0b11);
277 try testing.expectEqual(@as(usize, 0b11), x.fetchNand(0b10, .SeqCst));
278 try testing.expectEqual(~@as(usize, 0b10), x.load(.SeqCst));
279 try testing.expectEqual(~@as(usize, 0b10), x.fetchNand(0b00, .SeqCst));
280 try testing.expectEqual(~@as(usize, 0b00), x.load(.SeqCst));
277 try testing.expectEqual(@as(usize, 0b11), x.fetchNand(0b10, .seq_cst));
278 try testing.expectEqual(~@as(usize, 0b10), x.load(.seq_cst));
279 try testing.expectEqual(~@as(usize, 0b10), x.fetchNand(0b00, .seq_cst));
280 try testing.expectEqual(~@as(usize, 0b00), x.load(.seq_cst));
281281}
282282
283283test "Value.fetchOr" {
284284 var x = Value(usize).init(0b11);
285 try testing.expectEqual(@as(usize, 0b11), x.fetchOr(0b100, .SeqCst));
286 try testing.expectEqual(@as(usize, 0b111), x.load(.SeqCst));
287 try testing.expectEqual(@as(usize, 0b111), x.fetchOr(0b010, .SeqCst));
288 try testing.expectEqual(@as(usize, 0b111), x.load(.SeqCst));
285 try testing.expectEqual(@as(usize, 0b11), x.fetchOr(0b100, .seq_cst));
286 try testing.expectEqual(@as(usize, 0b111), x.load(.seq_cst));
287 try testing.expectEqual(@as(usize, 0b111), x.fetchOr(0b010, .seq_cst));
288 try testing.expectEqual(@as(usize, 0b111), x.load(.seq_cst));
289289}
290290
291291test "Value.fetchXor" {
292292 var x = Value(usize).init(0b11);
293 try testing.expectEqual(@as(usize, 0b11), x.fetchXor(0b10, .SeqCst));
294 try testing.expectEqual(@as(usize, 0b01), x.load(.SeqCst));
295 try testing.expectEqual(@as(usize, 0b01), x.fetchXor(0b01, .SeqCst));
296 try testing.expectEqual(@as(usize, 0b00), x.load(.SeqCst));
293 try testing.expectEqual(@as(usize, 0b11), x.fetchXor(0b10, .seq_cst));
294 try testing.expectEqual(@as(usize, 0b01), x.load(.seq_cst));
295 try testing.expectEqual(@as(usize, 0b01), x.fetchXor(0b01, .seq_cst));
296 try testing.expectEqual(@as(usize, 0b00), x.load(.seq_cst));
297297}
298298
299299test "Value.bitSet" {
......@@ -304,19 +304,19 @@ test "Value.bitSet" {
304304 const mask = @as(usize, 1) << bit;
305305
306306 // setting the bit should change the bit
307 try testing.expect(x.load(.SeqCst) & mask == 0);
308 try testing.expectEqual(@as(u1, 0), x.bitSet(bit, .SeqCst));
309 try testing.expect(x.load(.SeqCst) & mask != 0);
307 try testing.expect(x.load(.seq_cst) & mask == 0);
308 try testing.expectEqual(@as(u1, 0), x.bitSet(bit, .seq_cst));
309 try testing.expect(x.load(.seq_cst) & mask != 0);
310310
311311 // setting it again shouldn't change the bit
312 try testing.expectEqual(@as(u1, 1), x.bitSet(bit, .SeqCst));
313 try testing.expect(x.load(.SeqCst) & mask != 0);
312 try testing.expectEqual(@as(u1, 1), x.bitSet(bit, .seq_cst));
313 try testing.expect(x.load(.seq_cst) & mask != 0);
314314
315315 // all the previous bits should have not changed (still be set)
316316 for (0..bit_index) |prev_bit_index| {
317317 const prev_bit = @as(std.math.Log2Int(usize), @intCast(prev_bit_index));
318318 const prev_mask = @as(usize, 1) << prev_bit;
319 try testing.expect(x.load(.SeqCst) & prev_mask != 0);
319 try testing.expect(x.load(.seq_cst) & prev_mask != 0);
320320 }
321321 }
322322}
......@@ -330,19 +330,19 @@ test "Value.bitReset" {
330330 x.raw |= mask;
331331
332332 // unsetting the bit should change the bit
333 try testing.expect(x.load(.SeqCst) & mask != 0);
334 try testing.expectEqual(@as(u1, 1), x.bitReset(bit, .SeqCst));
335 try testing.expect(x.load(.SeqCst) & mask == 0);
333 try testing.expect(x.load(.seq_cst) & mask != 0);
334 try testing.expectEqual(@as(u1, 1), x.bitReset(bit, .seq_cst));
335 try testing.expect(x.load(.seq_cst) & mask == 0);
336336
337337 // unsetting it again shouldn't change the bit
338 try testing.expectEqual(@as(u1, 0), x.bitReset(bit, .SeqCst));
339 try testing.expect(x.load(.SeqCst) & mask == 0);
338 try testing.expectEqual(@as(u1, 0), x.bitReset(bit, .seq_cst));
339 try testing.expect(x.load(.seq_cst) & mask == 0);
340340
341341 // all the previous bits should have not changed (still be reset)
342342 for (0..bit_index) |prev_bit_index| {
343343 const prev_bit = @as(std.math.Log2Int(usize), @intCast(prev_bit_index));
344344 const prev_mask = @as(usize, 1) << prev_bit;
345 try testing.expect(x.load(.SeqCst) & prev_mask == 0);
345 try testing.expect(x.load(.seq_cst) & prev_mask == 0);
346346 }
347347 }
348348}
......@@ -355,19 +355,19 @@ test "Value.bitToggle" {
355355 const mask = @as(usize, 1) << bit;
356356
357357 // toggling the bit should change the bit
358 try testing.expect(x.load(.SeqCst) & mask == 0);
359 try testing.expectEqual(@as(u1, 0), x.bitToggle(bit, .SeqCst));
360 try testing.expect(x.load(.SeqCst) & mask != 0);
358 try testing.expect(x.load(.seq_cst) & mask == 0);
359 try testing.expectEqual(@as(u1, 0), x.bitToggle(bit, .seq_cst));
360 try testing.expect(x.load(.seq_cst) & mask != 0);
361361
362362 // toggling it again *should* change the bit
363 try testing.expectEqual(@as(u1, 1), x.bitToggle(bit, .SeqCst));
364 try testing.expect(x.load(.SeqCst) & mask == 0);
363 try testing.expectEqual(@as(u1, 1), x.bitToggle(bit, .seq_cst));
364 try testing.expect(x.load(.seq_cst) & mask == 0);
365365
366366 // all the previous bits should have not changed (still be toggled back)
367367 for (0..bit_index) |prev_bit_index| {
368368 const prev_bit = @as(std.math.Log2Int(usize), @intCast(prev_bit_index));
369369 const prev_mask = @as(usize, 1) << prev_bit;
370 try testing.expect(x.load(.SeqCst) & prev_mask == 0);
370 try testing.expect(x.load(.seq_cst) & prev_mask == 0);
371371 }
372372 }
373373}
lib/std/builtin.zig+6-6
......@@ -81,12 +81,12 @@ pub const SymbolVisibility = enum {
8181/// This data structure is used by the Zig language code generation and
8282/// therefore must be kept in sync with the compiler implementation.
8383pub const AtomicOrder = enum {
84 Unordered,
85 Monotonic,
86 Acquire,
87 Release,
88 AcqRel,
89 SeqCst,
84 unordered,
85 monotonic,
86 acquire,
87 release,
88 acq_rel,
89 seq_cst,
9090};
9191
9292/// This data structure is used by the Zig language code generation and
lib/std/child_process.zig+1-1
......@@ -1420,7 +1420,7 @@ fn windowsMakeAsyncPipe(rd: *?windows.HANDLE, wr: *?windows.HANDLE, sattr: *cons
14201420 const pipe_path = std.fmt.bufPrintZ(
14211421 &tmp_buf,
14221422 "\\\\.\\pipe\\zig-childprocess-{d}-{d}",
1423 .{ windows.kernel32.GetCurrentProcessId(), pipe_name_counter.fetchAdd(1, .Monotonic) },
1423 .{ windows.kernel32.GetCurrentProcessId(), pipe_name_counter.fetchAdd(1, .monotonic) },
14241424 ) catch unreachable;
14251425 const len = std.unicode.wtf8ToWtf16Le(&tmp_bufw, pipe_path) catch unreachable;
14261426 tmp_bufw[len] = 0;
lib/std/debug.zig+4-4
......@@ -461,7 +461,7 @@ pub fn panicImpl(trace: ?*const std.builtin.StackTrace, first_trace_addr: ?usize
461461 0 => {
462462 panic_stage = 1;
463463
464 _ = panicking.fetchAdd(1, .SeqCst);
464 _ = panicking.fetchAdd(1, .seq_cst);
465465
466466 // Make sure to release the mutex when done
467467 {
......@@ -503,7 +503,7 @@ pub fn panicImpl(trace: ?*const std.builtin.StackTrace, first_trace_addr: ?usize
503503
504504/// Must be called only after adding 1 to `panicking`. There are three callsites.
505505fn waitForOtherThreadToFinishPanicking() void {
506 if (panicking.fetchSub(1, .SeqCst) != 1) {
506 if (panicking.fetchSub(1, .seq_cst) != 1) {
507507 // Another thread is panicking, wait for the last one to finish
508508 // and call abort()
509509 if (builtin.single_threaded) unreachable;
......@@ -2587,7 +2587,7 @@ fn handleSegfaultPosix(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const any
25872587 nosuspend switch (panic_stage) {
25882588 0 => {
25892589 panic_stage = 1;
2590 _ = panicking.fetchAdd(1, .SeqCst);
2590 _ = panicking.fetchAdd(1, .seq_cst);
25912591
25922592 {
25932593 panic_mutex.lock();
......@@ -2663,7 +2663,7 @@ fn handleSegfaultWindowsExtra(
26632663 nosuspend switch (panic_stage) {
26642664 0 => {
26652665 panic_stage = 1;
2666 _ = panicking.fetchAdd(1, .SeqCst);
2666 _ = panicking.fetchAdd(1, .seq_cst);
26672667
26682668 {
26692669 panic_mutex.lock();
lib/std/heap.zig+4-4
......@@ -303,11 +303,11 @@ pub const HeapAllocator = switch (builtin.os.tag) {
303303
304304 const ptr_align = @as(usize, 1) << @as(Allocator.Log2Align, @intCast(log2_ptr_align));
305305 const amt = n + ptr_align - 1 + @sizeOf(usize);
306 const optional_heap_handle = @atomicLoad(?HeapHandle, &self.heap_handle, .SeqCst);
306 const optional_heap_handle = @atomicLoad(?HeapHandle, &self.heap_handle, .seq_cst);
307307 const heap_handle = optional_heap_handle orelse blk: {
308308 const options = if (builtin.single_threaded) os.windows.HEAP_NO_SERIALIZE else 0;
309309 const hh = os.windows.kernel32.HeapCreate(options, amt, 0) orelse return null;
310 const other_hh = @cmpxchgStrong(?HeapHandle, &self.heap_handle, null, hh, .SeqCst, .SeqCst) orelse break :blk hh;
310 const other_hh = @cmpxchgStrong(?HeapHandle, &self.heap_handle, null, hh, .seq_cst, .seq_cst) orelse break :blk hh;
311311 os.windows.HeapDestroy(hh);
312312 break :blk other_hh.?; // can't be null because of the cmpxchg
313313 };
......@@ -482,13 +482,13 @@ pub const FixedBufferAllocator = struct {
482482 const self: *FixedBufferAllocator = @ptrCast(@alignCast(ctx));
483483 _ = ra;
484484 const ptr_align = @as(usize, 1) << @as(Allocator.Log2Align, @intCast(log2_ptr_align));
485 var end_index = @atomicLoad(usize, &self.end_index, .SeqCst);
485 var end_index = @atomicLoad(usize, &self.end_index, .seq_cst);
486486 while (true) {
487487 const adjust_off = mem.alignPointerOffset(self.buffer.ptr + end_index, ptr_align) orelse return null;
488488 const adjusted_index = end_index + adjust_off;
489489 const new_end_index = adjusted_index + n;
490490 if (new_end_index > self.buffer.len) return null;
491 end_index = @cmpxchgWeak(usize, &self.end_index, end_index, new_end_index, .SeqCst, .SeqCst) orelse
491 end_index = @cmpxchgWeak(usize, &self.end_index, end_index, new_end_index, .seq_cst, .seq_cst) orelse
492492 return self.buffer[adjusted_index..new_end_index].ptr;
493493 }
494494 }
lib/std/heap/PageAllocator.zig+2-2
......@@ -30,7 +30,7 @@ fn alloc(_: *anyopaque, n: usize, log2_align: u8, ra: usize) ?[*]u8 {
3030 return @ptrCast(addr);
3131 }
3232
33 const hint = @atomicLoad(@TypeOf(std.heap.next_mmap_addr_hint), &std.heap.next_mmap_addr_hint, .Unordered);
33 const hint = @atomicLoad(@TypeOf(std.heap.next_mmap_addr_hint), &std.heap.next_mmap_addr_hint, .unordered);
3434 const slice = os.mmap(
3535 hint,
3636 aligned_len,
......@@ -41,7 +41,7 @@ fn alloc(_: *anyopaque, n: usize, log2_align: u8, ra: usize) ?[*]u8 {
4141 ) catch return null;
4242 assert(mem.isAligned(@intFromPtr(slice.ptr), mem.page_size));
4343 const new_hint: [*]align(mem.page_size) u8 = @alignCast(slice.ptr + aligned_len);
44 _ = @cmpxchgStrong(@TypeOf(std.heap.next_mmap_addr_hint), &std.heap.next_mmap_addr_hint, hint, new_hint, .Monotonic, .Monotonic);
44 _ = @cmpxchgStrong(@TypeOf(std.heap.next_mmap_addr_hint), &std.heap.next_mmap_addr_hint, hint, new_hint, .monotonic, .monotonic);
4545 return slice.ptr;
4646}
4747
lib/std/http/Client.zig+2-2
......@@ -1642,7 +1642,7 @@ pub fn open(
16421642
16431643 const host = uri.host orelse return error.UriMissingHost;
16441644
1645 if (protocol == .tls and @atomicLoad(bool, &client.next_https_rescan_certs, .Acquire)) {
1645 if (protocol == .tls and @atomicLoad(bool, &client.next_https_rescan_certs, .acquire)) {
16461646 if (disable_tls) unreachable;
16471647
16481648 client.ca_bundle_mutex.lock();
......@@ -1650,7 +1650,7 @@ pub fn open(
16501650
16511651 if (client.next_https_rescan_certs) {
16521652 client.ca_bundle.rescan(client.allocator) catch return error.CertificateBundleLoadFailure;
1653 @atomicStore(bool, &client.next_https_rescan_certs, false, .Release);
1653 @atomicStore(bool, &client.next_https_rescan_certs, false, .release);
16541654 }
16551655 }
16561656
lib/std/once.zig+2-2
......@@ -17,7 +17,7 @@ pub fn Once(comptime f: fn () void) type {
1717 /// first time.
1818 /// The invocations are thread-safe.
1919 pub fn call(self: *@This()) void {
20 if (@atomicLoad(bool, &self.done, .Acquire))
20 if (@atomicLoad(bool, &self.done, .acquire))
2121 return;
2222
2323 return self.callSlow();
......@@ -32,7 +32,7 @@ pub fn Once(comptime f: fn () void) type {
3232 // The first thread to acquire the mutex gets to run the initializer
3333 if (!self.done) {
3434 f();
35 @atomicStore(bool, &self.done, true, .Release);
35 @atomicStore(bool, &self.done, true, .release);
3636 }
3737 }
3838 };
lib/std/os.zig+5-5
......@@ -436,7 +436,7 @@ fn fchmodat1(dirfd: fd_t, path: []const u8, mode: mode_t, flags: u32) FChmodAtEr
436436fn fchmodat2(dirfd: fd_t, path: []const u8, mode: mode_t, flags: u32) FChmodAtError!void {
437437 const path_c = try toPosixPath(path);
438438 const use_fchmodat2 = (builtin.os.isAtLeast(.linux, .{ .major = 6, .minor = 6, .patch = 0 }) orelse false) and
439 has_fchmodat2_syscall.load(.Monotonic);
439 has_fchmodat2_syscall.load(.monotonic);
440440 while (use_fchmodat2) {
441441 // Later on this should be changed to `system.fchmodat2`
442442 // when the musl/glibc add a wrapper.
......@@ -458,7 +458,7 @@ fn fchmodat2(dirfd: fd_t, path: []const u8, mode: mode_t, flags: u32) FChmodAtEr
458458 .ROFS => return error.ReadOnlyFileSystem,
459459
460460 .NOSYS => { // Use fallback.
461 has_fchmodat2_syscall.store(false, .Monotonic);
461 has_fchmodat2_syscall.store(false, .monotonic);
462462 break;
463463 },
464464 else => |err| return unexpectedErrno(err),
......@@ -729,7 +729,7 @@ pub fn abort() noreturn {
729729 const global = struct {
730730 var abort_entered: bool = false;
731731 };
732 while (@cmpxchgWeak(bool, &global.abort_entered, false, true, .SeqCst, .SeqCst)) |_| {}
732 while (@cmpxchgWeak(bool, &global.abort_entered, false, true, .seq_cst, .seq_cst)) |_| {}
733733 }
734734
735735 // Install default handler so that the tkill below will terminate.
......@@ -6809,7 +6809,7 @@ pub fn copy_file_range(fd_in: fd_t, off_in: u64, fd_out: fd_t, off_out: u64, len
68096809 if ((comptime builtin.os.isAtLeast(.freebsd, .{ .major = 13, .minor = 0, .patch = 0 }) orelse false) or
68106810 ((comptime builtin.os.isAtLeast(.linux, .{ .major = 4, .minor = 5, .patch = 0 }) orelse false and
68116811 std.c.versionCheck(.{ .major = 2, .minor = 27, .patch = 0 })) and
6812 has_copy_file_range_syscall.load(.Monotonic)))
6812 has_copy_file_range_syscall.load(.monotonic)))
68136813 {
68146814 var off_in_copy: i64 = @bitCast(off_in);
68156815 var off_out_copy: i64 = @bitCast(off_out);
......@@ -6844,7 +6844,7 @@ pub fn copy_file_range(fd_in: fd_t, off_in: u64, fd_out: fd_t, off_out: u64, len
68446844 .TXTBSY => return error.SwapFile,
68456845 .XDEV => break, // support for cross-filesystem copy added in Linux 5.3, use fallback
68466846 .NOSYS => { // syscall added in Linux 4.5, use fallback
6847 has_copy_file_range_syscall.store(false, .Monotonic);
6847 has_copy_file_range_syscall.store(false, .monotonic);
68486848 break;
68496849 },
68506850 else => |err| return unexpectedErrno(err),
lib/std/os/linux.zig+2-2
......@@ -1334,7 +1334,7 @@ const vdso_clock_gettime_ty = *align(1) const fn (i32, *timespec) callconv(.C) u
13341334
13351335pub fn clock_gettime(clk_id: i32, tp: *timespec) usize {
13361336 if (@hasDecl(VDSO, "CGT_SYM")) {
1337 const ptr = @atomicLoad(?*const anyopaque, &vdso_clock_gettime, .Unordered);
1337 const ptr = @atomicLoad(?*const anyopaque, &vdso_clock_gettime, .unordered);
13381338 if (ptr) |fn_ptr| {
13391339 const f = @as(vdso_clock_gettime_ty, @ptrCast(fn_ptr));
13401340 const rc = f(clk_id, tp);
......@@ -1351,7 +1351,7 @@ fn init_vdso_clock_gettime(clk: i32, ts: *timespec) callconv(.C) usize {
13511351 const ptr = @as(?*const anyopaque, @ptrFromInt(vdso.lookup(VDSO.CGT_VER, VDSO.CGT_SYM)));
13521352 // Note that we may not have a VDSO at all, update the stub address anyway
13531353 // so that clock_gettime will fall back on the good old (and slow) syscall
1354 @atomicStore(?*const anyopaque, &vdso_clock_gettime, ptr, .Monotonic);
1354 @atomicStore(?*const anyopaque, &vdso_clock_gettime, ptr, .monotonic);
13551355 // Call into the VDSO if available
13561356 if (ptr) |fn_ptr| {
13571357 const f = @as(vdso_clock_gettime_ty, @ptrCast(fn_ptr));
lib/std/os/linux/IoUring.zig+7-7
......@@ -133,7 +133,7 @@ pub fn deinit(self: *IoUring) void {
133133/// alternative. In Zig, we have first-class error handling... so let's use it.
134134/// Matches the implementation of io_uring_get_sqe() in liburing.
135135pub fn get_sqe(self: *IoUring) !*linux.io_uring_sqe {
136 const head = @atomicLoad(u32, self.sq.head, .Acquire);
136 const head = @atomicLoad(u32, self.sq.head, .acquire);
137137 // Remember that these head and tail offsets wrap around every four billion operations.
138138 // We must therefore use wrapping addition and subtraction to avoid a runtime crash.
139139 const next = self.sq.sqe_tail +% 1;
......@@ -222,7 +222,7 @@ pub fn flush_sq(self: *IoUring) u32 {
222222 self.sq.sqe_head +%= 1;
223223 }
224224 // Ensure that the kernel can actually see the SQE updates when it sees the tail update.
225 @atomicStore(u32, self.sq.tail, tail, .Release);
225 @atomicStore(u32, self.sq.tail, tail, .release);
226226 }
227227 return self.sq_ready();
228228}
......@@ -234,7 +234,7 @@ pub fn flush_sq(self: *IoUring) u32 {
234234pub fn sq_ring_needs_enter(self: *IoUring, flags: *u32) bool {
235235 assert(flags.* == 0);
236236 if ((self.flags & linux.IORING_SETUP_SQPOLL) == 0) return true;
237 if ((@atomicLoad(u32, self.sq.flags, .Unordered) & linux.IORING_SQ_NEED_WAKEUP) != 0) {
237 if ((@atomicLoad(u32, self.sq.flags, .unordered) & linux.IORING_SQ_NEED_WAKEUP) != 0) {
238238 flags.* |= linux.IORING_ENTER_SQ_WAKEUP;
239239 return true;
240240 }
......@@ -248,14 +248,14 @@ pub fn sq_ring_needs_enter(self: *IoUring, flags: *u32) bool {
248248pub fn sq_ready(self: *IoUring) u32 {
249249 // Always use the shared ring state (i.e. head and not sqe_head) to avoid going out of sync,
250250 // see https://github.com/axboe/liburing/issues/92.
251 return self.sq.sqe_tail -% @atomicLoad(u32, self.sq.head, .Acquire);
251 return self.sq.sqe_tail -% @atomicLoad(u32, self.sq.head, .acquire);
252252}
253253
254254/// Returns the number of CQEs in the completion queue, i.e. its length.
255255/// These are CQEs that the application is yet to consume.
256256/// Matches the implementation of io_uring_cq_ready in liburing.
257257pub fn cq_ready(self: *IoUring) u32 {
258 return @atomicLoad(u32, self.cq.tail, .Acquire) -% self.cq.head.*;
258 return @atomicLoad(u32, self.cq.tail, .acquire) -% self.cq.head.*;
259259}
260260
261261/// Copies as many CQEs as are ready, and that can fit into the destination `cqes` slice.
......@@ -313,7 +313,7 @@ pub fn copy_cqe(ring: *IoUring) !linux.io_uring_cqe {
313313
314314/// Matches the implementation of cq_ring_needs_flush() in liburing.
315315pub fn cq_ring_needs_flush(self: *IoUring) bool {
316 return (@atomicLoad(u32, self.sq.flags, .Unordered) & linux.IORING_SQ_CQ_OVERFLOW) != 0;
316 return (@atomicLoad(u32, self.sq.flags, .unordered) & linux.IORING_SQ_CQ_OVERFLOW) != 0;
317317}
318318
319319/// For advanced use cases only that implement custom completion queue methods.
......@@ -331,7 +331,7 @@ pub fn cqe_seen(self: *IoUring, cqe: *linux.io_uring_cqe) void {
331331pub fn cq_advance(self: *IoUring, count: u32) void {
332332 if (count > 0) {
333333 // Ensure the kernel only sees the new head value after the CQEs have been read.
334 @atomicStore(u32, self.cq.head, self.cq.head.* +% count, .Release);
334 @atomicStore(u32, self.cq.head, self.cq.head.* +% count, .release);
335335 }
336336}
337337
lib/std/os/test.zig+1-1
......@@ -425,7 +425,7 @@ fn start1() u8 {
425425}
426426
427427fn start2(ctx: *i32) u8 {
428 _ = @atomicRmw(i32, ctx, AtomicRmwOp.Add, 1, AtomicOrder.SeqCst);
428 _ = @atomicRmw(i32, ctx, AtomicRmwOp.Add, 1, AtomicOrder.seq_cst);
429429 return 0;
430430}
431431
src/Sema.zig+18-18
......@@ -6450,8 +6450,8 @@ fn zirFence(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) Co
64506450 .needed_comptime_reason = "atomic order of @fence must be comptime-known",
64516451 });
64526452
6453 if (@intFromEnum(order) < @intFromEnum(std.builtin.AtomicOrder.Acquire)) {
6454 return sema.fail(block, order_src, "atomic ordering must be Acquire or stricter", .{});
6453 if (@intFromEnum(order) < @intFromEnum(std.builtin.AtomicOrder.acquire)) {
6454 return sema.fail(block, order_src, "atomic ordering must be acquire or stricter", .{});
64556455 }
64566456
64576457 _ = try block.addInst(.{
......@@ -23894,17 +23894,17 @@ fn zirCmpxchg(
2389423894 .needed_comptime_reason = "atomic order of cmpxchg failure must be comptime-known",
2389523895 });
2389623896
23897 if (@intFromEnum(success_order) < @intFromEnum(std.builtin.AtomicOrder.Monotonic)) {
23898 return sema.fail(block, success_order_src, "success atomic ordering must be Monotonic or stricter", .{});
23897 if (@intFromEnum(success_order) < @intFromEnum(std.builtin.AtomicOrder.monotonic)) {
23898 return sema.fail(block, success_order_src, "success atomic ordering must be monotonic or stricter", .{});
2389923899 }
23900 if (@intFromEnum(failure_order) < @intFromEnum(std.builtin.AtomicOrder.Monotonic)) {
23901 return sema.fail(block, failure_order_src, "failure atomic ordering must be Monotonic or stricter", .{});
23900 if (@intFromEnum(failure_order) < @intFromEnum(std.builtin.AtomicOrder.monotonic)) {
23901 return sema.fail(block, failure_order_src, "failure atomic ordering must be monotonic or stricter", .{});
2390223902 }
2390323903 if (@intFromEnum(failure_order) > @intFromEnum(success_order)) {
2390423904 return sema.fail(block, failure_order_src, "failure atomic ordering must be no stricter than success", .{});
2390523905 }
23906 if (failure_order == .Release or failure_order == .AcqRel) {
23907 return sema.fail(block, failure_order_src, "failure atomic ordering must not be Release or AcqRel", .{});
23906 if (failure_order == .release or failure_order == .acq_rel) {
23907 return sema.fail(block, failure_order_src, "failure atomic ordering must not be release or acq_rel", .{});
2390823908 }
2390923909
2391023910 const result_ty = try mod.optionalType(elem_ty.toIntern());
......@@ -24346,11 +24346,11 @@ fn zirAtomicLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2434624346 });
2434724347
2434824348 switch (order) {
24349 .Release, .AcqRel => {
24349 .release, .acq_rel => {
2435024350 return sema.fail(
2435124351 block,
2435224352 order_src,
24353 "@atomicLoad atomic ordering must not be Release or AcqRel",
24353 "@atomicLoad atomic ordering must not be release or acq_rel",
2435424354 .{},
2435524355 );
2435624356 },
......@@ -24412,8 +24412,8 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2441224412 .needed_comptime_reason = "atomic order of @atomicRmW must be comptime-known",
2441324413 });
2441424414
24415 if (order == .Unordered) {
24416 return sema.fail(block, order_src, "@atomicRmw atomic ordering must not be Unordered", .{});
24415 if (order == .unordered) {
24416 return sema.fail(block, order_src, "@atomicRmw atomic ordering must not be unordered", .{});
2441724417 }
2441824418
2441924419 // special case zero bit types
......@@ -24482,18 +24482,18 @@ fn zirAtomicStore(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
2448224482 });
2448324483
2448424484 const air_tag: Air.Inst.Tag = switch (order) {
24485 .Acquire, .AcqRel => {
24485 .acquire, .acq_rel => {
2448624486 return sema.fail(
2448724487 block,
2448824488 order_src,
24489 "@atomicStore atomic ordering must not be Acquire or AcqRel",
24489 "@atomicStore atomic ordering must not be acquire or acq_rel",
2449024490 .{},
2449124491 );
2449224492 },
24493 .Unordered => .atomic_store_unordered,
24494 .Monotonic => .atomic_store_monotonic,
24495 .Release => .atomic_store_release,
24496 .SeqCst => .atomic_store_seq_cst,
24493 .unordered => .atomic_store_unordered,
24494 .monotonic => .atomic_store_monotonic,
24495 .release => .atomic_store_release,
24496 .seq_cst => .atomic_store_seq_cst,
2449724497 };
2449824498
2449924499 return sema.storePtr2(block, src, ptr, ptr_src, operand, operand_src, air_tag);
src/arch/aarch64/CodeGen.zig+4-4
......@@ -815,10 +815,10 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
815815 .call_never_tail => try self.airCall(inst, .never_tail),
816816 .call_never_inline => try self.airCall(inst, .never_inline),
817817
818 .atomic_store_unordered => try self.airAtomicStore(inst, .Unordered),
819 .atomic_store_monotonic => try self.airAtomicStore(inst, .Monotonic),
820 .atomic_store_release => try self.airAtomicStore(inst, .Release),
821 .atomic_store_seq_cst => try self.airAtomicStore(inst, .SeqCst),
818 .atomic_store_unordered => try self.airAtomicStore(inst, .unordered),
819 .atomic_store_monotonic => try self.airAtomicStore(inst, .monotonic),
820 .atomic_store_release => try self.airAtomicStore(inst, .release),
821 .atomic_store_seq_cst => try self.airAtomicStore(inst, .seq_cst),
822822
823823 .struct_field_ptr_index_0 => try self.airStructFieldPtrIndex(inst, 0),
824824 .struct_field_ptr_index_1 => try self.airStructFieldPtrIndex(inst, 1),
src/arch/arm/CodeGen.zig+4-4
......@@ -801,10 +801,10 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
801801 .call_never_tail => try self.airCall(inst, .never_tail),
802802 .call_never_inline => try self.airCall(inst, .never_inline),
803803
804 .atomic_store_unordered => try self.airAtomicStore(inst, .Unordered),
805 .atomic_store_monotonic => try self.airAtomicStore(inst, .Monotonic),
806 .atomic_store_release => try self.airAtomicStore(inst, .Release),
807 .atomic_store_seq_cst => try self.airAtomicStore(inst, .SeqCst),
804 .atomic_store_unordered => try self.airAtomicStore(inst, .unordered),
805 .atomic_store_monotonic => try self.airAtomicStore(inst, .monotonic),
806 .atomic_store_release => try self.airAtomicStore(inst, .release),
807 .atomic_store_seq_cst => try self.airAtomicStore(inst, .seq_cst),
808808
809809 .struct_field_ptr_index_0 => try self.airStructFieldPtrIndex(inst, 0),
810810 .struct_field_ptr_index_1 => try self.airStructFieldPtrIndex(inst, 1),
src/arch/riscv64/CodeGen.zig+4-4
......@@ -634,10 +634,10 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
634634 .call_never_tail => try self.airCall(inst, .never_tail),
635635 .call_never_inline => try self.airCall(inst, .never_inline),
636636
637 .atomic_store_unordered => try self.airAtomicStore(inst, .Unordered),
638 .atomic_store_monotonic => try self.airAtomicStore(inst, .Monotonic),
639 .atomic_store_release => try self.airAtomicStore(inst, .Release),
640 .atomic_store_seq_cst => try self.airAtomicStore(inst, .SeqCst),
637 .atomic_store_unordered => try self.airAtomicStore(inst, .unordered),
638 .atomic_store_monotonic => try self.airAtomicStore(inst, .monotonic),
639 .atomic_store_release => try self.airAtomicStore(inst, .release),
640 .atomic_store_seq_cst => try self.airAtomicStore(inst, .seq_cst),
641641
642642 .struct_field_ptr_index_0 => try self.airStructFieldPtrIndex(inst, 0),
643643 .struct_field_ptr_index_1 => try self.airStructFieldPtrIndex(inst, 1),
src/arch/x86_64/CodeGen.zig+10-10
......@@ -2111,10 +2111,10 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
21112111 .call_never_tail => try self.airCall(inst, .never_tail),
21122112 .call_never_inline => try self.airCall(inst, .never_inline),
21132113
2114 .atomic_store_unordered => try self.airAtomicStore(inst, .Unordered),
2115 .atomic_store_monotonic => try self.airAtomicStore(inst, .Monotonic),
2116 .atomic_store_release => try self.airAtomicStore(inst, .Release),
2117 .atomic_store_seq_cst => try self.airAtomicStore(inst, .SeqCst),
2114 .atomic_store_unordered => try self.airAtomicStore(inst, .unordered),
2115 .atomic_store_monotonic => try self.airAtomicStore(inst, .monotonic),
2116 .atomic_store_release => try self.airAtomicStore(inst, .release),
2117 .atomic_store_seq_cst => try self.airAtomicStore(inst, .seq_cst),
21182118
21192119 .struct_field_ptr_index_0 => try self.airStructFieldPtrIndex(inst, 0),
21202120 .struct_field_ptr_index_1 => try self.airStructFieldPtrIndex(inst, 1),
......@@ -11977,9 +11977,9 @@ fn airFrameAddress(self: *Self, inst: Air.Inst.Index) !void {
1197711977fn airFence(self: *Self, inst: Air.Inst.Index) !void {
1197811978 const order = self.air.instructions.items(.data)[@intFromEnum(inst)].fence;
1197911979 switch (order) {
11980 .Unordered, .Monotonic => unreachable,
11981 .Acquire, .Release, .AcqRel => {},
11982 .SeqCst => try self.asmOpOnly(.{ ._, .mfence }),
11980 .unordered, .monotonic => unreachable,
11981 .acquire, .release, .acq_rel => {},
11982 .seq_cst => try self.asmOpOnly(.{ ._, .mfence }),
1198311983 }
1198411984 self.finishAirBookkeeping();
1198511985}
......@@ -15747,9 +15747,9 @@ fn atomicOp(
1574715747 .Xor => .xor,
1574815748 else => unreachable,
1574915749 } else switch (order) {
15750 .Unordered, .Monotonic, .Release, .AcqRel => .mov,
15751 .Acquire => unreachable,
15752 .SeqCst => .xchg,
15750 .unordered, .monotonic, .release, .acq_rel => .mov,
15751 .acquire => unreachable,
15752 .seq_cst => .xchg,
1575315753 };
1575415754
1575515755 const dst_reg = try self.register_manager.allocReg(null, abi.RegisterClass.gp);
src/codegen/c.zig+9-9
......@@ -3278,10 +3278,10 @@ fn genBodyInner(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail,
32783278
32793279 .int_from_ptr => try airIntFromPtr(f, inst),
32803280
3281 .atomic_store_unordered => try airAtomicStore(f, inst, toMemoryOrder(.Unordered)),
3282 .atomic_store_monotonic => try airAtomicStore(f, inst, toMemoryOrder(.Monotonic)),
3283 .atomic_store_release => try airAtomicStore(f, inst, toMemoryOrder(.Release)),
3284 .atomic_store_seq_cst => try airAtomicStore(f, inst, toMemoryOrder(.SeqCst)),
3281 .atomic_store_unordered => try airAtomicStore(f, inst, toMemoryOrder(.unordered)),
3282 .atomic_store_monotonic => try airAtomicStore(f, inst, toMemoryOrder(.monotonic)),
3283 .atomic_store_release => try airAtomicStore(f, inst, toMemoryOrder(.release)),
3284 .atomic_store_seq_cst => try airAtomicStore(f, inst, toMemoryOrder(.seq_cst)),
32853285
32863286 .struct_field_ptr_index_0 => try airStructFieldPtrIndex(f, inst, 0),
32873287 .struct_field_ptr_index_1 => try airStructFieldPtrIndex(f, inst, 1),
......@@ -7482,11 +7482,11 @@ fn airCVaCopy(f: *Function, inst: Air.Inst.Index) !CValue {
74827482fn toMemoryOrder(order: std.builtin.AtomicOrder) [:0]const u8 {
74837483 return switch (order) {
74847484 // Note: unordered is actually even less atomic than relaxed
7485 .Unordered, .Monotonic => "zig_memory_order_relaxed",
7486 .Acquire => "zig_memory_order_acquire",
7487 .Release => "zig_memory_order_release",
7488 .AcqRel => "zig_memory_order_acq_rel",
7489 .SeqCst => "zig_memory_order_seq_cst",
7485 .unordered, .monotonic => "zig_memory_order_relaxed",
7486 .acquire => "zig_memory_order_acquire",
7487 .release => "zig_memory_order_release",
7488 .acq_rel => "zig_memory_order_acq_rel",
7489 .seq_cst => "zig_memory_order_seq_cst",
74907490 };
74917491}
74927492
src/codegen/llvm.zig+7-7
......@@ -1278,7 +1278,7 @@ pub const Object = struct {
12781278
12791279 const reloc_mode: llvm.RelocMode = if (pic)
12801280 .PIC
1281 else if (self.module.comp.config.link_mode == .Dynamic)
1281 else if (self.module.comp.config.link_mode == .dynamic)
12821282 llvm.RelocMode.DynamicNoPIC
12831283 else
12841284 .Static;
......@@ -10801,12 +10801,12 @@ pub const FuncGen = struct {
1080110801
1080210802fn toLlvmAtomicOrdering(atomic_order: std.builtin.AtomicOrder) Builder.AtomicOrdering {
1080310803 return switch (atomic_order) {
10804 .Unordered => .unordered,
10805 .Monotonic => .monotonic,
10806 .Acquire => .acquire,
10807 .Release => .release,
10808 .AcqRel => .acq_rel,
10809 .SeqCst => .seq_cst,
10804 .unordered => .unordered,
10805 .monotonic => .monotonic,
10806 .acquire => .acquire,
10807 .release => .release,
10808 .acq_rel => .acq_rel,
10809 .seq_cst => .seq_cst,
1081010810 };
1081110811}
1081210812
src/codegen/llvm/Builder.zig+1-1
......@@ -8398,7 +8398,7 @@ pub const Metadata = enum(u32) {
83988398 fmt_str = fmt_str ++ ")\n";
83998399
84008400 var fmt_args: @Type(.{ .Struct = .{
8401 .layout = .Auto,
8401 .layout = .auto,
84028402 .fields = &fields,
84038403 .decls = &.{},
84048404 .is_tuple = false,
src/codegen/llvm/bitcode_writer.zig+2-2
......@@ -415,8 +415,8 @@ fn BufType(comptime T: type, comptime min_len: usize) type {
415415 .Enum => |info| info.tag_type,
416416 .Bool => u1,
417417 .Struct => |info| switch (info.layout) {
418 .Auto, .Extern => @compileError("Unsupported type: " ++ @typeName(T)),
419 .Packed => std.meta.Int(.unsigned, @bitSizeOf(T)),
418 .auto, .@"extern" => @compileError("Unsupported type: " ++ @typeName(T)),
419 .@"packed" => std.meta.Int(.unsigned, @bitSizeOf(T)),
420420 },
421421 else => @compileError("Unsupported type: " ++ @typeName(T)),
422422 })));
src/crash_report.zig+2-2
......@@ -376,7 +376,7 @@ const PanicSwitch = struct {
376376 };
377377 state.* = new_state;
378378
379 _ = panicking.fetchAdd(1, .SeqCst);
379 _ = panicking.fetchAdd(1, .seq_cst);
380380
381381 state.recover_stage = .release_ref_count;
382382
......@@ -458,7 +458,7 @@ const PanicSwitch = struct {
458458 noinline fn releaseRefCount(state: *volatile PanicState) noreturn {
459459 state.recover_stage = .abort;
460460
461 if (panicking.fetchSub(1, .SeqCst) != 1) {
461 if (panicking.fetchSub(1, .seq_cst) != 1) {
462462 // Another thread is panicking, wait for the last one to finish
463463 // and call abort()
464464
src/main.zig+3-3
......@@ -4145,8 +4145,8 @@ fn progressThread(progress: *std.Progress, server: *const Server, reset: *std.Th
41454145 buf.appendSlice("... ") catch {};
41464146 }
41474147 need_ellipse = false;
4148 const eti = @atomicLoad(usize, &node.unprotected_estimated_total_items, .Monotonic);
4149 const completed_items = @atomicLoad(usize, &node.unprotected_completed_items, .Monotonic);
4148 const eti = @atomicLoad(usize, &node.unprotected_estimated_total_items, .monotonic);
4149 const completed_items = @atomicLoad(usize, &node.unprotected_completed_items, .monotonic);
41504150 const current_item = completed_items + 1;
41514151 if (node.name.len != 0 or eti > 0) {
41524152 if (node.name.len != 0) {
......@@ -4163,7 +4163,7 @@ fn progressThread(progress: *std.Progress, server: *const Server, reset: *std.Th
41634163 need_ellipse = false;
41644164 }
41654165 }
4166 maybe_node = @atomicLoad(?*std.Progress.Node, &node.recently_updated_child, .Acquire);
4166 maybe_node = @atomicLoad(?*std.Progress.Node, &node.recently_updated_child, .acquire);
41674167 }
41684168 }
41694169
src/print_air.zig+4-4
......@@ -303,10 +303,10 @@ const Writer = struct {
303303 .fence => try w.writeFence(s, inst),
304304 .atomic_load => try w.writeAtomicLoad(s, inst),
305305 .prefetch => try w.writePrefetch(s, inst),
306 .atomic_store_unordered => try w.writeAtomicStore(s, inst, .Unordered),
307 .atomic_store_monotonic => try w.writeAtomicStore(s, inst, .Monotonic),
308 .atomic_store_release => try w.writeAtomicStore(s, inst, .Release),
309 .atomic_store_seq_cst => try w.writeAtomicStore(s, inst, .SeqCst),
306 .atomic_store_unordered => try w.writeAtomicStore(s, inst, .unordered),
307 .atomic_store_monotonic => try w.writeAtomicStore(s, inst, .monotonic),
308 .atomic_store_release => try w.writeAtomicStore(s, inst, .release),
309 .atomic_store_seq_cst => try w.writeAtomicStore(s, inst, .seq_cst),
310310 .atomic_rmw => try w.writeAtomicRmw(s, inst),
311311 .field_parent_ptr => try w.writeFieldParentPtr(s, inst),
312312 .wasm_memory_size => try w.writeWasmMemorySize(s, inst),
test/behavior/atomics.zig+59-59
......@@ -22,18 +22,18 @@ test "cmpxchg" {
2222
2323fn testCmpxchg() !void {
2424 var x: i32 = 1234;
25 if (@cmpxchgWeak(i32, &x, 99, 5678, .SeqCst, .SeqCst)) |x1| {
25 if (@cmpxchgWeak(i32, &x, 99, 5678, .seq_cst, .seq_cst)) |x1| {
2626 try expect(x1 == 1234);
2727 } else {
2828 @panic("cmpxchg should have failed");
2929 }
3030
31 while (@cmpxchgWeak(i32, &x, 1234, 5678, .SeqCst, .SeqCst)) |x1| {
31 while (@cmpxchgWeak(i32, &x, 1234, 5678, .seq_cst, .seq_cst)) |x1| {
3232 try expect(x1 == 1234);
3333 }
3434 try expect(x == 5678);
3535
36 try expect(@cmpxchgStrong(i32, &x, 5678, 42, .SeqCst, .SeqCst) == null);
36 try expect(@cmpxchgStrong(i32, &x, 5678, 42, .seq_cst, .seq_cst) == null);
3737 try expect(x == 42);
3838}
3939
......@@ -43,7 +43,7 @@ test "fence" {
4343 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
4444
4545 var x: i32 = 1234;
46 @fence(.SeqCst);
46 @fence(.seq_cst);
4747 x = 5678;
4848}
4949
......@@ -60,18 +60,18 @@ test "atomicrmw and atomicload" {
6060}
6161
6262fn testAtomicRmw(ptr: *u8) !void {
63 const prev_value = @atomicRmw(u8, ptr, .Xchg, 42, .SeqCst);
63 const prev_value = @atomicRmw(u8, ptr, .Xchg, 42, .seq_cst);
6464 try expect(prev_value == 200);
6565 comptime {
6666 var x: i32 = 1234;
6767 const y: i32 = 12345;
68 try expect(@atomicLoad(i32, &x, .SeqCst) == 1234);
69 try expect(@atomicLoad(i32, &y, .SeqCst) == 12345);
68 try expect(@atomicLoad(i32, &x, .seq_cst) == 1234);
69 try expect(@atomicLoad(i32, &y, .seq_cst) == 12345);
7070 }
7171}
7272
7373fn testAtomicLoad(ptr: *u8) !void {
74 const x = @atomicLoad(u8, ptr, .SeqCst);
74 const x = @atomicLoad(u8, ptr, .seq_cst);
7575 try expect(x == 42);
7676}
7777
......@@ -85,18 +85,18 @@ test "cmpxchg with ptr" {
8585 var data2: i32 = 5678;
8686 var data3: i32 = 9101;
8787 var x: *i32 = &data1;
88 if (@cmpxchgWeak(*i32, &x, &data2, &data3, .SeqCst, .SeqCst)) |x1| {
88 if (@cmpxchgWeak(*i32, &x, &data2, &data3, .seq_cst, .seq_cst)) |x1| {
8989 try expect(x1 == &data1);
9090 } else {
9191 @panic("cmpxchg should have failed");
9292 }
9393
94 while (@cmpxchgWeak(*i32, &x, &data1, &data3, .SeqCst, .SeqCst)) |x1| {
94 while (@cmpxchgWeak(*i32, &x, &data1, &data3, .seq_cst, .seq_cst)) |x1| {
9595 try expect(x1 == &data1);
9696 }
9797 try expect(x == &data3);
9898
99 try expect(@cmpxchgStrong(*i32, &x, &data3, &data2, .SeqCst, .SeqCst) == null);
99 try expect(@cmpxchgStrong(*i32, &x, &data3, &data2, .seq_cst, .seq_cst) == null);
100100 try expect(x == &data2);
101101}
102102
......@@ -108,7 +108,7 @@ test "cmpxchg with ignored result" {
108108
109109 var x: i32 = 1234;
110110
111 _ = @cmpxchgStrong(i32, &x, 1234, 5678, .Monotonic, .Monotonic);
111 _ = @cmpxchgStrong(i32, &x, 1234, 5678, .monotonic, .monotonic);
112112
113113 try expect(5678 == x);
114114}
......@@ -127,18 +127,18 @@ test "128-bit cmpxchg" {
127127
128128fn test_u128_cmpxchg() !void {
129129 var x: u128 align(16) = 1234;
130 if (@cmpxchgWeak(u128, &x, 99, 5678, .SeqCst, .SeqCst)) |x1| {
130 if (@cmpxchgWeak(u128, &x, 99, 5678, .seq_cst, .seq_cst)) |x1| {
131131 try expect(x1 == 1234);
132132 } else {
133133 @panic("cmpxchg should have failed");
134134 }
135135
136 while (@cmpxchgWeak(u128, &x, 1234, 5678, .SeqCst, .SeqCst)) |x1| {
136 while (@cmpxchgWeak(u128, &x, 1234, 5678, .seq_cst, .seq_cst)) |x1| {
137137 try expect(x1 == 1234);
138138 }
139139 try expect(x == 5678);
140140
141 try expect(@cmpxchgStrong(u128, &x, 5678, 42, .SeqCst, .SeqCst) == null);
141 try expect(@cmpxchgStrong(u128, &x, 5678, 42, .seq_cst, .seq_cst) == null);
142142 try expect(x == 42);
143143}
144144
......@@ -155,7 +155,7 @@ test "cmpxchg on a global variable" {
155155 return error.SkipZigTest;
156156 }
157157
158 _ = @cmpxchgWeak(u32, &a_global_variable, 1234, 42, .Acquire, .Monotonic);
158 _ = @cmpxchgWeak(u32, &a_global_variable, 1234, 42, .acquire, .monotonic);
159159 try expect(a_global_variable == 42);
160160}
161161
......@@ -168,12 +168,12 @@ test "atomic load and rmw with enum" {
168168 const Value = enum(u8) { a, b, c };
169169 var x = Value.a;
170170
171 try expect(@atomicLoad(Value, &x, .SeqCst) != .b);
171 try expect(@atomicLoad(Value, &x, .seq_cst) != .b);
172172
173 _ = @atomicRmw(Value, &x, .Xchg, .c, .SeqCst);
174 try expect(@atomicLoad(Value, &x, .SeqCst) == .c);
175 try expect(@atomicLoad(Value, &x, .SeqCst) != .a);
176 try expect(@atomicLoad(Value, &x, .SeqCst) != .b);
173 _ = @atomicRmw(Value, &x, .Xchg, .c, .seq_cst);
174 try expect(@atomicLoad(Value, &x, .seq_cst) == .c);
175 try expect(@atomicLoad(Value, &x, .seq_cst) != .a);
176 try expect(@atomicLoad(Value, &x, .seq_cst) != .b);
177177}
178178
179179test "atomic store" {
......@@ -183,10 +183,10 @@ test "atomic store" {
183183 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
184184
185185 var x: u32 = 0;
186 @atomicStore(u32, &x, 1, .SeqCst);
187 try expect(@atomicLoad(u32, &x, .SeqCst) == 1);
188 @atomicStore(u32, &x, 12345678, .SeqCst);
189 try expect(@atomicLoad(u32, &x, .SeqCst) == 12345678);
186 @atomicStore(u32, &x, 1, .seq_cst);
187 try expect(@atomicLoad(u32, &x, .seq_cst) == 1);
188 @atomicStore(u32, &x, 12345678, .seq_cst);
189 try expect(@atomicLoad(u32, &x, .seq_cst) == 12345678);
190190}
191191
192192test "atomic store comptime" {
......@@ -201,10 +201,10 @@ test "atomic store comptime" {
201201
202202fn testAtomicStore() !void {
203203 var x: u32 = 0;
204 @atomicStore(u32, &x, 1, .SeqCst);
205 try expect(@atomicLoad(u32, &x, .SeqCst) == 1);
206 @atomicStore(u32, &x, 12345678, .SeqCst);
207 try expect(@atomicLoad(u32, &x, .SeqCst) == 12345678);
204 @atomicStore(u32, &x, 1, .seq_cst);
205 try expect(@atomicLoad(u32, &x, .seq_cst) == 1);
206 @atomicStore(u32, &x, 12345678, .seq_cst);
207 try expect(@atomicLoad(u32, &x, .seq_cst) == 12345678);
208208}
209209
210210test "atomicrmw with floats" {
......@@ -224,15 +224,15 @@ test "atomicrmw with floats" {
224224fn testAtomicRmwFloat() !void {
225225 var x: f32 = 0;
226226 try expect(x == 0);
227 _ = @atomicRmw(f32, &x, .Xchg, 1, .SeqCst);
227 _ = @atomicRmw(f32, &x, .Xchg, 1, .seq_cst);
228228 try expect(x == 1);
229 _ = @atomicRmw(f32, &x, .Add, 5, .SeqCst);
229 _ = @atomicRmw(f32, &x, .Add, 5, .seq_cst);
230230 try expect(x == 6);
231 _ = @atomicRmw(f32, &x, .Sub, 2, .SeqCst);
231 _ = @atomicRmw(f32, &x, .Sub, 2, .seq_cst);
232232 try expect(x == 4);
233 _ = @atomicRmw(f32, &x, .Max, 13, .SeqCst);
233 _ = @atomicRmw(f32, &x, .Max, 13, .seq_cst);
234234 try expect(x == 13);
235 _ = @atomicRmw(f32, &x, .Min, 42, .SeqCst);
235 _ = @atomicRmw(f32, &x, .Min, 42, .seq_cst);
236236 try expect(x == 13);
237237}
238238
......@@ -266,46 +266,46 @@ fn testAtomicRmwInt(comptime signedness: std.builtin.Signedness, comptime N: usi
266266 const int = std.meta.Int(signedness, N);
267267
268268 var x: int = 1;
269 var res = @atomicRmw(int, &x, .Xchg, 3, .SeqCst);
269 var res = @atomicRmw(int, &x, .Xchg, 3, .seq_cst);
270270 try expect(x == 3 and res == 1);
271271
272 res = @atomicRmw(int, &x, .Add, 3, .SeqCst);
272 res = @atomicRmw(int, &x, .Add, 3, .seq_cst);
273273 var y: int = 3;
274274 try expect(res == y);
275275 y = y + 3;
276276 try expect(x == y);
277277
278 res = @atomicRmw(int, &x, .Sub, 1, .SeqCst);
278 res = @atomicRmw(int, &x, .Sub, 1, .seq_cst);
279279 try expect(res == y);
280280 y = y - 1;
281281 try expect(x == y);
282282
283 res = @atomicRmw(int, &x, .And, 4, .SeqCst);
283 res = @atomicRmw(int, &x, .And, 4, .seq_cst);
284284 try expect(res == y);
285285 y = y & 4;
286286 try expect(x == y);
287287
288 res = @atomicRmw(int, &x, .Nand, 4, .SeqCst);
288 res = @atomicRmw(int, &x, .Nand, 4, .seq_cst);
289289 try expect(res == y);
290290 y = ~(y & 4);
291291 try expect(x == y);
292292
293 res = @atomicRmw(int, &x, .Or, 6, .SeqCst);
293 res = @atomicRmw(int, &x, .Or, 6, .seq_cst);
294294 try expect(res == y);
295295 y = y | 6;
296296 try expect(x == y);
297297
298 res = @atomicRmw(int, &x, .Xor, 2, .SeqCst);
298 res = @atomicRmw(int, &x, .Xor, 2, .seq_cst);
299299 try expect(res == y);
300300 y = y ^ 2;
301301 try expect(x == y);
302302
303 res = @atomicRmw(int, &x, .Max, 1, .SeqCst);
303 res = @atomicRmw(int, &x, .Max, 1, .seq_cst);
304304 try expect(res == y);
305305 y = @max(y, 1);
306306 try expect(x == y);
307307
308 res = @atomicRmw(int, &x, .Min, 1, .SeqCst);
308 res = @atomicRmw(int, &x, .Min, 1, .seq_cst);
309309 try expect(res == y);
310310 y = @min(y, 1);
311311 try expect(x == y);
......@@ -333,53 +333,53 @@ fn testAtomicRmwInt128(comptime signedness: std.builtin.Signedness) !void {
333333 const replacement: int = 0x00000000_00000005_00000000_00000003;
334334
335335 var x: int align(16) = initial;
336 var res = @atomicRmw(int, &x, .Xchg, replacement, .SeqCst);
336 var res = @atomicRmw(int, &x, .Xchg, replacement, .seq_cst);
337337 try expect(x == replacement and res == initial);
338338
339339 var operator: int = 0x00000001_00000000_20000000_00000000;
340 res = @atomicRmw(int, &x, .Add, operator, .SeqCst);
340 res = @atomicRmw(int, &x, .Add, operator, .seq_cst);
341341 var y: int = replacement;
342342 try expect(res == y);
343343 y = y + operator;
344344 try expect(x == y);
345345
346346 operator = 0x00000000_10000000_00000000_20000000;
347 res = @atomicRmw(int, &x, .Sub, operator, .SeqCst);
347 res = @atomicRmw(int, &x, .Sub, operator, .seq_cst);
348348 try expect(res == y);
349349 y = y - operator;
350350 try expect(x == y);
351351
352352 operator = 0x12345678_87654321_12345678_87654321;
353 res = @atomicRmw(int, &x, .And, operator, .SeqCst);
353 res = @atomicRmw(int, &x, .And, operator, .seq_cst);
354354 try expect(res == y);
355355 y = y & operator;
356356 try expect(x == y);
357357
358358 operator = 0x00000000_10000000_00000000_20000000;
359 res = @atomicRmw(int, &x, .Nand, operator, .SeqCst);
359 res = @atomicRmw(int, &x, .Nand, operator, .seq_cst);
360360 try expect(res == y);
361361 y = ~(y & operator);
362362 try expect(x == y);
363363
364364 operator = 0x12340000_56780000_67890000_98760000;
365 res = @atomicRmw(int, &x, .Or, operator, .SeqCst);
365 res = @atomicRmw(int, &x, .Or, operator, .seq_cst);
366366 try expect(res == y);
367367 y = y | operator;
368368 try expect(x == y);
369369
370370 operator = 0x0a0b0c0d_0e0f0102_03040506_0708090a;
371 res = @atomicRmw(int, &x, .Xor, operator, .SeqCst);
371 res = @atomicRmw(int, &x, .Xor, operator, .seq_cst);
372372 try expect(res == y);
373373 y = y ^ operator;
374374 try expect(x == y);
375375
376376 operator = 0x00000000_10000000_00000000_20000000;
377 res = @atomicRmw(int, &x, .Max, operator, .SeqCst);
377 res = @atomicRmw(int, &x, .Max, operator, .seq_cst);
378378 try expect(res == y);
379379 y = @max(y, operator);
380380 try expect(x == y);
381381
382 res = @atomicRmw(int, &x, .Min, operator, .SeqCst);
382 res = @atomicRmw(int, &x, .Min, operator, .seq_cst);
383383 try expect(res == y);
384384 y = @min(y, operator);
385385 try expect(x == y);
......@@ -405,13 +405,13 @@ test "atomics with different types" {
405405
406406fn testAtomicsWithType(comptime T: type, a: T, b: T) !void {
407407 var x: T = b;
408 @atomicStore(T, &x, a, .SeqCst);
408 @atomicStore(T, &x, a, .seq_cst);
409409 try expect(x == a);
410 try expect(@atomicLoad(T, &x, .SeqCst) == a);
411 try expect(@atomicRmw(T, &x, .Xchg, b, .SeqCst) == a);
412 try expect(@cmpxchgStrong(T, &x, b, a, .SeqCst, .SeqCst) == null);
410 try expect(@atomicLoad(T, &x, .seq_cst) == a);
411 try expect(@atomicRmw(T, &x, .Xchg, b, .seq_cst) == a);
412 try expect(@cmpxchgStrong(T, &x, b, a, .seq_cst, .seq_cst) == null);
413413 if (@sizeOf(T) != 0)
414 try expect(@cmpxchgStrong(T, &x, b, a, .SeqCst, .SeqCst).? == a);
414 try expect(@cmpxchgStrong(T, &x, b, a, .seq_cst, .seq_cst).? == a);
415415}
416416
417417test "return @atomicStore, using it as a void value" {
......@@ -425,12 +425,12 @@ test "return @atomicStore, using it as a void value" {
425425 value: usize,
426426
427427 pub fn store(self: *A, value: usize) void {
428 return @atomicStore(usize, &self.value, value, .Unordered);
428 return @atomicStore(usize, &self.value, value, .unordered);
429429 }
430430
431431 pub fn store2(self: *A, value: usize) void {
432432 return switch (value) {
433 else => @atomicStore(usize, &self.value, value, .Unordered),
433 else => @atomicStore(usize, &self.value, value, .unordered),
434434 };
435435 }
436436 };
test/behavior/builtin_functions_returning_void_or_noreturn.zig+2-2
......@@ -14,10 +14,10 @@ test {
1414 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
1515
1616 var val: u8 = undefined;
17 try testing.expectEqual({}, @atomicStore(u8, &val, 0, .Unordered));
17 try testing.expectEqual({}, @atomicStore(u8, &val, 0, .unordered));
1818 try testing.expectEqual(void, @TypeOf(@breakpoint()));
1919 try testing.expectEqual({}, @export(x, .{ .name = "x" }));
20 try testing.expectEqual({}, @fence(.Acquire));
20 try testing.expectEqual({}, @fence(.acquire));
2121 try testing.expectEqual({}, @memcpy(@as([*]u8, @ptrFromInt(1))[0..0], @as([*]u8, @ptrFromInt(1))[0..0]));
2222 try testing.expectEqual({}, @memset(@as([*]u8, @ptrFromInt(1))[0..0], undefined));
2323 try testing.expectEqual(noreturn, @TypeOf(if (true) @panic("") else {}));
test/cases/compile_errors/atomic_orderings_of_atomicStore_Acquire_or_AcqRel.zig+2-2
......@@ -1,10 +1,10 @@
11export fn entry() void {
22 var x: u32 = 0;
3 @atomicStore(u32, &x, 1, .Acquire);
3 @atomicStore(u32, &x, 1, .acquire);
44}
55
66// error
77// backend=stage2
88// target=native
99//
10// :3:31: error: @atomicStore atomic ordering must not be Acquire or AcqRel
10// :3:31: error: @atomicStore atomic ordering must not be acquire or acq_rel
test/cases/compile_errors/atomic_orderings_of_cmpxchg-failure_stricter_than_success.zig+1-1
......@@ -1,7 +1,7 @@
11const AtomicOrder = @import("std").builtin.AtomicOrder;
22export fn f() void {
33 var x: i32 = 1234;
4 while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.Monotonic, AtomicOrder.SeqCst)) {}
4 while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.monotonic, AtomicOrder.seq_cst)) {}
55}
66
77// error
test/cases/compile_errors/atomic_orderings_of_cmpxchg-success_Monotonic_or_stricter.zig+2-2
......@@ -1,11 +1,11 @@
11const AtomicOrder = @import("std").builtin.AtomicOrder;
22export fn f() void {
33 var x: i32 = 1234;
4 while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.Unordered, AtomicOrder.Unordered)) {}
4 while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.unordered, AtomicOrder.unordered)) {}
55}
66
77// error
88// backend=stage2
99// target=native
1010//
11// :4:58: error: success atomic ordering must be Monotonic or stricter
11// :4:58: error: success atomic ordering must be monotonic or stricter
test/cases/compile_errors/atomic_orderings_of_fence_Acquire_or_stricter.zig+2-2
......@@ -1,9 +1,9 @@
11export fn entry() void {
2 @fence(.Monotonic);
2 @fence(.monotonic);
33}
44
55// error
66// backend=stage2
77// target=native
88//
9// :2:13: error: atomic ordering must be Acquire or stricter
9// :2:13: error: atomic ordering must be acquire or stricter
test/cases/compile_errors/atomicrmw_with_bool_op_not_.Xchg.zig+1-1
......@@ -1,6 +1,6 @@
11export fn entry() void {
22 var x = false;
3 _ = @atomicRmw(bool, &x, .Add, true, .SeqCst);
3 _ = @atomicRmw(bool, &x, .Add, true, .seq_cst);
44}
55
66// error
test/cases/compile_errors/atomicrmw_with_enum_op_not_.Xchg.zig+1-1
......@@ -6,7 +6,7 @@ export fn entry() void {
66 d,
77 };
88 var x: E = .a;
9 _ = @atomicRmw(E, &x, .Add, .b, .SeqCst);
9 _ = @atomicRmw(E, &x, .Add, .b, .seq_cst);
1010}
1111
1212// error
test/cases/compile_errors/atomicrmw_with_float_op_not_.Xchg_.Add_.Sub_.Max_or_.Min.zig+1-1
......@@ -1,6 +1,6 @@
11export fn entry() void {
22 var x: f32 = 0;
3 _ = @atomicRmw(f32, &x, .And, 2, .SeqCst);
3 _ = @atomicRmw(f32, &x, .And, 2, .seq_cst);
44}
55
66// error
test/cases/compile_errors/cmpxchg_with_float.zig+1-1
......@@ -1,6 +1,6 @@
11export fn entry() void {
22 var x: f32 = 0;
3 _ = @cmpxchgWeak(f32, &x, 1, 2, .SeqCst, .SeqCst);
3 _ = @cmpxchgWeak(f32, &x, 1, 2, .seq_cst, .seq_cst);
44}
55
66// error
test/cases/compile_errors/passing_a_not-aligned-enough_pointer_to_cmpxchg.zig+1-1
......@@ -1,7 +1,7 @@
11const AtomicOrder = @import("std").builtin.AtomicOrder;
22export fn entry() bool {
33 var x: i32 align(1) = 1234;
4 while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) {}
4 while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.seq_cst, AtomicOrder.seq_cst)) {}
55 return x == 5678;
66}
77