| ... | @@ -48,38 +48,38 @@ pub fn Atomic(comptime T: type) type { | ... | @@ -48,38 +48,38 @@ pub fn Atomic(comptime T: type) type { |
| 48 | }; | 48 | }; |
| 49 | } | 49 | } |
| 50 | | 50 | |
| 51 | pub fn swap(self: *Self, value: T, comptime ordering: Ordering) callconv(.Inline) T { | 51 | pub inline fn swap(self: *Self, value: T, comptime ordering: Ordering) T { |
| 52 | return self.rmw(.Xchg, value, ordering); | 52 | return self.rmw(.Xchg, value, ordering); |
| 53 | } | 53 | } |
| 54 | | 54 | |
| 55 | pub fn compareAndSwap( | 55 | pub inline fn compareAndSwap( |
| 56 | self: *Self, | 56 | self: *Self, |
| 57 | compare: T, | 57 | compare: T, |
| 58 | exchange: T, | 58 | exchange: T, |
| 59 | comptime success: Ordering, | 59 | comptime success: Ordering, |
| 60 | comptime failure: Ordering, | 60 | comptime failure: Ordering, |
| 61 | ) callconv(.Inline) ?T { | 61 | ) ?T { |
| 62 | return self.cmpxchg(true, compare, exchange, success, failure); | 62 | return self.cmpxchg(true, compare, exchange, success, failure); |
| 63 | } | 63 | } |
| 64 | | 64 | |
| 65 | pub fn tryCompareAndSwap( | 65 | pub inline fn tryCompareAndSwap( |
| 66 | self: *Self, | 66 | self: *Self, |
| 67 | compare: T, | 67 | compare: T, |
| 68 | exchange: T, | 68 | exchange: T, |
| 69 | comptime success: Ordering, | 69 | comptime success: Ordering, |
| 70 | comptime failure: Ordering, | 70 | comptime failure: Ordering, |
| 71 | ) callconv(.Inline) ?T { | 71 | ) ?T { |
| 72 | return self.cmpxchg(false, compare, exchange, success, failure); | 72 | return self.cmpxchg(false, compare, exchange, success, failure); |
| 73 | } | 73 | } |
| 74 | | 74 | |
| 75 | fn cmpxchg( | 75 | inline fn cmpxchg( |
| 76 | self: *Self, | 76 | self: *Self, |
| 77 | comptime is_strong: bool, | 77 | comptime is_strong: bool, |
| 78 | compare: T, | 78 | compare: T, |
| 79 | exchange: T, | 79 | exchange: T, |
| 80 | comptime success: Ordering, | 80 | comptime success: Ordering, |
| 81 | comptime failure: Ordering, | 81 | comptime failure: Ordering, |
| 82 | ) callconv(.Inline) ?T { | 82 | ) ?T { |
| 83 | if (success == .Unordered or failure == .Unordered) { | 83 | if (success == .Unordered or failure == .Unordered) { |
| 84 | @compileError(@tagName(Ordering.Unordered) ++ " is only allowed on atomic loads and stores"); | 84 | @compileError(@tagName(Ordering.Unordered) ++ " is only allowed on atomic loads and stores"); |
| 85 | } | 85 | } |
| ... | @@ -103,12 +103,12 @@ pub fn Atomic(comptime T: type) type { | ... | @@ -103,12 +103,12 @@ pub fn Atomic(comptime T: type) type { |
| 103 | }; | 103 | }; |
| 104 | } | 104 | } |
| 105 | | 105 | |
| 106 | fn rmw( | 106 | inline fn rmw( |
| 107 | self: *Self, | 107 | self: *Self, |
| 108 | comptime op: std.builtin.AtomicRmwOp, | 108 | comptime op: std.builtin.AtomicRmwOp, |
| 109 | value: T, | 109 | value: T, |
| 110 | comptime ordering: Ordering, | 110 | comptime ordering: Ordering, |
| 111 | ) callconv(.Inline) T { | 111 | ) T { |
| 112 | return @atomicRmw(T, &self.value, op, value, ordering); | 112 | return @atomicRmw(T, &self.value, op, value, ordering); |
| 113 | } | 113 | } |
| 114 | | 114 | |
| ... | @@ -117,37 +117,37 @@ pub fn Atomic(comptime T: type) type { | ... | @@ -117,37 +117,37 @@ pub fn Atomic(comptime T: type) type { |
| 117 | } | 117 | } |
| 118 | | 118 | |
| 119 | pub usingnamespace exportWhen(std.meta.trait.isNumber(T), struct { | 119 | pub usingnamespace exportWhen(std.meta.trait.isNumber(T), struct { |
| 120 | pub fn fetchAdd(self: *Self, value: T, comptime ordering: Ordering) callconv(.Inline) T { | 120 | pub inline fn fetchAdd(self: *Self, value: T, comptime ordering: Ordering) T { |
| 121 | return self.rmw(.Add, value, ordering); | 121 | return self.rmw(.Add, value, ordering); |
| 122 | } | 122 | } |
| 123 | | 123 | |
| 124 | pub fn fetchSub(self: *Self, value: T, comptime ordering: Ordering) callconv(.Inline) T { | 124 | pub inline fn fetchSub(self: *Self, value: T, comptime ordering: Ordering) T { |
| 125 | return self.rmw(.Sub, value, ordering); | 125 | return self.rmw(.Sub, value, ordering); |
| 126 | } | 126 | } |
| 127 | | 127 | |
| 128 | pub fn fetchMin(self: *Self, value: T, comptime ordering: Ordering) callconv(.Inline) T { | 128 | pub inline fn fetchMin(self: *Self, value: T, comptime ordering: Ordering) T { |
| 129 | return self.rmw(.Min, value, ordering); | 129 | return self.rmw(.Min, value, ordering); |
| 130 | } | 130 | } |
| 131 | | 131 | |
| 132 | pub fn fetchMax(self: *Self, value: T, comptime ordering: Ordering) callconv(.Inline) T { | 132 | pub inline fn fetchMax(self: *Self, value: T, comptime ordering: Ordering) T { |
| 133 | return self.rmw(.Max, value, ordering); | 133 | return self.rmw(.Max, value, ordering); |
| 134 | } | 134 | } |
| 135 | }); | 135 | }); |
| 136 | | 136 | |
| 137 | pub usingnamespace exportWhen(std.meta.trait.isIntegral(T), struct { | 137 | pub usingnamespace exportWhen(std.meta.trait.isIntegral(T), struct { |
| 138 | pub fn fetchAnd(self: *Self, value: T, comptime ordering: Ordering) callconv(.Inline) T { | 138 | pub inline fn fetchAnd(self: *Self, value: T, comptime ordering: Ordering) T { |
| 139 | return self.rmw(.And, value, ordering); | 139 | return self.rmw(.And, value, ordering); |
| 140 | } | 140 | } |
| 141 | | 141 | |
| 142 | pub fn fetchNand(self: *Self, value: T, comptime ordering: Ordering) callconv(.Inline) T { | 142 | pub inline fn fetchNand(self: *Self, value: T, comptime ordering: Ordering) T { |
| 143 | return self.rmw(.Nand, value, ordering); | 143 | return self.rmw(.Nand, value, ordering); |
| 144 | } | 144 | } |
| 145 | | 145 | |
| 146 | pub fn fetchOr(self: *Self, value: T, comptime ordering: Ordering) callconv(.Inline) T { | 146 | pub inline fn fetchOr(self: *Self, value: T, comptime ordering: Ordering) T { |
| 147 | return self.rmw(.Or, value, ordering); | 147 | return self.rmw(.Or, value, ordering); |
| 148 | } | 148 | } |
| 149 | | 149 | |
| 150 | pub fn fetchXor(self: *Self, value: T, comptime ordering: Ordering) callconv(.Inline) T { | 150 | pub inline fn fetchXor(self: *Self, value: T, comptime ordering: Ordering) T { |
| 151 | return self.rmw(.Xor, value, ordering); | 151 | return self.rmw(.Xor, value, ordering); |
| 152 | } | 152 | } |
| 153 | | 153 | |
| ... | @@ -158,24 +158,24 @@ pub fn Atomic(comptime T: type) type { | ... | @@ -158,24 +158,24 @@ pub fn Atomic(comptime T: type) type { |
| 158 | Toggle, | 158 | Toggle, |
| 159 | }; | 159 | }; |
| 160 | | 160 | |
| 161 | pub fn bitSet(self: *Self, bit: Bit, comptime ordering: Ordering) callconv(.Inline) u1 { | 161 | pub inline fn bitSet(self: *Self, bit: Bit, comptime ordering: Ordering) u1 { |
| 162 | return bitRmw(self, .Set, bit, ordering); | 162 | return bitRmw(self, .Set, bit, ordering); |
| 163 | } | 163 | } |
| 164 | | 164 | |
| 165 | pub fn bitReset(self: *Self, bit: Bit, comptime ordering: Ordering) callconv(.Inline) u1 { | 165 | pub inline fn bitReset(self: *Self, bit: Bit, comptime ordering: Ordering) u1 { |
| 166 | return bitRmw(self, .Reset, bit, ordering); | 166 | return bitRmw(self, .Reset, bit, ordering); |
| 167 | } | 167 | } |
| 168 | | 168 | |
| 169 | pub fn bitToggle(self: *Self, bit: Bit, comptime ordering: Ordering) callconv(.Inline) u1 { | 169 | pub inline fn bitToggle(self: *Self, bit: Bit, comptime ordering: Ordering) u1 { |
| 170 | return bitRmw(self, .Toggle, bit, ordering); | 170 | return bitRmw(self, .Toggle, bit, ordering); |
| 171 | } | 171 | } |
| 172 | | 172 | |
| 173 | fn bitRmw( | 173 | inline fn bitRmw( |
| 174 | self: *Self, | 174 | self: *Self, |
| 175 | comptime op: BitRmwOp, | 175 | comptime op: BitRmwOp, |
| 176 | bit: Bit, | 176 | bit: Bit, |
| 177 | comptime ordering: Ordering, | 177 | comptime ordering: Ordering, |
| 178 | ) callconv(.Inline) u1 { | 178 | ) u1 { |
| 179 | // x86 supports dedicated bitwise instructions | 179 | // x86 supports dedicated bitwise instructions |
| 180 | if (comptime target.cpu.arch.isX86() and @sizeOf(T) >= 2 and @sizeOf(T) <= 8) { | 180 | if (comptime target.cpu.arch.isX86() and @sizeOf(T) >= 2 and @sizeOf(T) <= 8) { |
| 181 | const instruction = switch (op) { | 181 | const instruction = switch (op) { |