| author | |
| committer | |
| log | 5e91cc2fe38cd5fd4a481629ba1d72a8c66b46e6 |
| tree | 280a1c10a5a922776a67f01efc3a16b3f9191c15 |
| parent | 584451140843f8e1524f3cebf0ca3ab580685b3d |
2 files changed, 24 insertions(+), 0 deletions(-)
lib/std/atomic/bool.zig+12| ... | @@ -21,14 +21,26 @@ pub const Bool = extern struct { | ... | @@ -21,14 +21,26 @@ pub const Bool = extern struct { |
| 21 | // xchg is only valid rmw operation for a bool | 21 | // xchg is only valid rmw operation for a bool |
| 22 | /// Atomically modifies memory and then returns the previous value. | 22 | /// Atomically modifies memory and then returns the previous value. |
| 23 | pub fn xchg(self: *Self, operand: bool, comptime ordering: std.builtin.AtomicOrder) bool { | 23 | pub fn xchg(self: *Self, operand: bool, comptime ordering: std.builtin.AtomicOrder) bool { |
| 24 | switch (ordering) { | ||
| 25 | .Monotonic, .Acquire, .Release, .AcqRel, .SeqCst => {}, | ||
| 26 | else => @compileError("Invalid ordering '" ++ @tagName(ordering) ++ "' for a RMW operation"), | ||
| 27 | } | ||
| 24 | return @atomicRmw(bool, &self.unprotected_value, .Xchg, operand, ordering); | 28 | return @atomicRmw(bool, &self.unprotected_value, .Xchg, operand, ordering); |
| 25 | } | 29 | } |
| 26 | 30 | ||
| 27 | pub fn load(self: *Self, comptime ordering: std.builtin.AtomicOrder) bool { | 31 | pub fn load(self: *Self, comptime ordering: std.builtin.AtomicOrder) bool { |
| 32 | switch (ordering) { | ||
| 33 | .Unordered, .Monotonic, .Acquire, .SeqCst => {}, | ||
| 34 | else => @compileError("Invalid ordering '" ++ @tagName(ordering) ++ "' for a load operation"), | ||
| 35 | } | ||
| 28 | return @atomicLoad(bool, &self.unprotected_value, ordering); | 36 | return @atomicLoad(bool, &self.unprotected_value, ordering); |
| 29 | } | 37 | } |
| 30 | 38 | ||
| 31 | pub fn store(self: *Self, value: bool, comptime ordering: std.builtin.AtomicOrder) void { | 39 | pub fn store(self: *Self, value: bool, comptime ordering: std.builtin.AtomicOrder) void { |
| 40 | switch (ordering) { | ||
| 41 | .Unordered, .Monotonic, .Release, .SeqCst => {}, | ||
| 42 | else => @compileError("Invalid ordering '" ++ @tagName(ordering) ++ "' for a store operation"), | ||
| 43 | } | ||
| 32 | @atomicStore(bool, &self.unprotected_value, value, ordering); | 44 | @atomicStore(bool, &self.unprotected_value, value, ordering); |
| 33 | } | 45 | } |
| 34 | }; | 46 | }; |
lib/std/atomic/int.zig+12| ... | @@ -24,14 +24,26 @@ pub fn Int(comptime T: type) type { | ... | @@ -24,14 +24,26 @@ pub fn Int(comptime T: type) type { |
| 24 | 24 | ||
| 25 | /// Read, Modify, Write | 25 | /// Read, Modify, Write |
| 26 | pub fn rmw(self: *Self, comptime op: builtin.AtomicRmwOp, operand: T, comptime ordering: builtin.AtomicOrder) T { | 26 | pub fn rmw(self: *Self, comptime op: builtin.AtomicRmwOp, operand: T, comptime ordering: builtin.AtomicOrder) T { |
| 27 | switch (ordering) { | ||
| 28 | .Monotonic, .Acquire, .Release, .AcqRel, .SeqCst => {}, | ||
| 29 | else => @compileError("Invalid ordering '" ++ @tagName(ordering) ++ "' for a RMW operation"), | ||
| 30 | } | ||
| 27 | return @atomicRmw(T, &self.unprotected_value, op, operand, ordering); | 31 | return @atomicRmw(T, &self.unprotected_value, op, operand, ordering); |
| 28 | } | 32 | } |
| 29 | 33 | ||
| 30 | pub fn load(self: *Self, comptime ordering: builtin.AtomicOrder) T { | 34 | pub fn load(self: *Self, comptime ordering: builtin.AtomicOrder) T { |
| 35 | switch (ordering) { | ||
| 36 | .Unordered, .Monotonic, .Acquire, .SeqCst => {}, | ||
| 37 | else => @compileError("Invalid ordering '" ++ @tagName(ordering) ++ "' for a load operation"), | ||
| 38 | } | ||
| 31 | return @atomicLoad(T, &self.unprotected_value, ordering); | 39 | return @atomicLoad(T, &self.unprotected_value, ordering); |
| 32 | } | 40 | } |
| 33 | 41 | ||
| 34 | pub fn store(self: *Self, value: T, comptime ordering: builtin.AtomicOrder) void { | 42 | pub fn store(self: *Self, value: T, comptime ordering: builtin.AtomicOrder) void { |
| 43 | switch (ordering) { | ||
| 44 | .Unordered, .Monotonic, .Release, .SeqCst => {}, | ||
| 45 | else => @compileError("Invalid ordering '" ++ @tagName(ordering) ++ "' for a store operation"), | ||
| 46 | } | ||
| 35 | @atomicStore(T, &self.unprotected_value, value, ordering); | 47 | @atomicStore(T, &self.unprotected_value, value, ordering); |
| 36 | } | 48 | } |
| 37 | 49 |