zig/doc/langref/not_atomic_cmpxchgStrong.zig

12 lines
268 B
Zig
Raw Normal View History

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