aboutsummaryrefslogtreecommitdiff
path: root/lib/std/atomic/int.zig
diff options
context:
space:
mode:
Diffstat (limited to 'lib/std/atomic/int.zig')
-rw-r--r--lib/std/atomic/int.zig15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/std/atomic/int.zig b/lib/std/atomic/int.zig
index 155a340b0a..b06575e05f 100644
--- a/lib/std/atomic/int.zig
+++ b/lib/std/atomic/int.zig
@@ -10,6 +10,9 @@ const testing = std.testing;
/// Thread-safe, lock-free integer
pub fn Int(comptime T: type) type {
+ if (!std.meta.trait.isIntegral(T))
+ @compileError("Expected integral type, got '" ++ @typeName(T) ++ "'");
+
return extern struct {
unprotected_value: T,
@@ -21,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);
}