mirror of
https://github.com/ziglang/zig.git
synced 2024-11-27 07:32:44 +00:00
12 lines
268 B
Zig
12 lines
268 B
Zig
|
fn cmpxchgStrongButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_value: T) ?T {
|
||
|
const old_value = ptr.*;
|
||
|
if (old_value == expected_value) {
|
||
|
ptr.* = new_value;
|
||
|
return null;
|
||
|
} else {
|
||
|
return old_value;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// syntax
|