diff --git a/lib/std/atomic/bool.zig b/lib/std/atomic/bool.zig index c686fdfae0..27a265bbc1 100644 --- a/lib/std/atomic/bool.zig +++ b/lib/std/atomic/bool.zig @@ -21,14 +21,26 @@ pub const Bool = extern struct { // xchg is only valid rmw operation for a bool /// Atomically modifies memory and then returns the previous value. pub fn xchg(self: *Self, operand: bool, comptime ordering: std.builtin.AtomicOrder) bool { + switch (ordering) { + .Monotonic, .Acquire, .Release, .AcqRel, .SeqCst => {}, + else => @compileError("Invalid ordering '" ++ @tagName(ordering) ++ "' for a RMW operation"), + } return @atomicRmw(bool, &self.unprotected_value, .Xchg, operand, ordering); } pub fn load(self: *Self, comptime ordering: std.builtin.AtomicOrder) bool { + switch (ordering) { + .Unordered, .Monotonic, .Acquire, .SeqCst => {}, + else => @compileError("Invalid ordering '" ++ @tagName(ordering) ++ "' for a load operation"), + } return @atomicLoad(bool, &self.unprotected_value, ordering); } pub fn store(self: *Self, value: bool, comptime ordering: std.builtin.AtomicOrder) void { + switch (ordering) { + .Unordered, .Monotonic, .Release, .SeqCst => {}, + else => @compileError("Invalid ordering '" ++ @tagName(ordering) ++ "' for a store operation"), + } @atomicStore(bool, &self.unprotected_value, value, ordering); } }; diff --git a/lib/std/atomic/int.zig b/lib/std/atomic/int.zig index cdbf4ca81e..b06575e05f 100644 --- a/lib/std/atomic/int.zig +++ b/lib/std/atomic/int.zig @@ -24,14 +24,26 @@ pub fn Int(comptime T: type) type { /// Read, Modify, Write pub fn rmw(self: *Self, comptime op: builtin.AtomicRmwOp, operand: T, comptime ordering: builtin.AtomicOrder) T { + switch (ordering) { + .Monotonic, .Acquire, .Release, .AcqRel, .SeqCst => {}, + else => @compileError("Invalid ordering '" ++ @tagName(ordering) ++ "' for a RMW operation"), + } return @atomicRmw(T, &self.unprotected_value, op, operand, ordering); } pub fn load(self: *Self, comptime ordering: builtin.AtomicOrder) T { + switch (ordering) { + .Unordered, .Monotonic, .Acquire, .SeqCst => {}, + else => @compileError("Invalid ordering '" ++ @tagName(ordering) ++ "' for a load operation"), + } return @atomicLoad(T, &self.unprotected_value, ordering); } pub fn store(self: *Self, value: T, comptime ordering: builtin.AtomicOrder) void { + switch (ordering) { + .Unordered, .Monotonic, .Release, .SeqCst => {}, + else => @compileError("Invalid ordering '" ++ @tagName(ordering) ++ "' for a store operation"), + } @atomicStore(T, &self.unprotected_value, value, ordering); }