zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit b4d134a0d2ee238cab70f1e967b2172edbec1b41 (tree)
parent e938344100da959308aa27dee1295e5ce02efc30
Author: Alex Rønne Petersen <alex@alexrp.com>
Date:   Sat, 21 Mar 2026 04:14:44 +0100

Merge pull request 'std: audit (most) usages of `cmpxchgWeak`' (#31608) from justusk/zig:cmpxchg-xchg into master

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31608
Reviewed-by: Alex Rønne Petersen <alex@alexrp.com>

Diffstat:
Mlib/std/Io/Threaded.zig | 21+--------------------
Mlib/std/Progress.zig | 4++--
2 files changed, 3 insertions(+), 22 deletions(-)

diff --git a/lib/std/Io/Threaded.zig b/lib/std/Io/Threaded.zig @@ -1337,25 +1337,6 @@ const Thread = struct { return @ptrFromInt(@as(usize, @bitCast(split))); } }; - - /// Same as `Io.Mutex.lock` but avoids the VTable. - fn mutexLock(m: *Io.Mutex) Io.Cancelable!void { - const initial_state = m.state.cmpxchgWeak( - .unlocked, - .locked_once, - .acquire, - .monotonic, - ) orelse { - @branchHint(.likely); - return; - }; - if (initial_state == .contended) { - try Thread.futexWait(@ptrCast(&m.state.raw), @intFromEnum(Io.Mutex.State.contended), null); - } - while (m.state.swap(.contended, .acquire) != .unlocked) { - try Thread.futexWait(@ptrCast(&m.state.raw), @intFromEnum(Io.Mutex.State.contended), null); - } - } }; const Syscall = struct { @@ -18663,7 +18644,7 @@ fn condWait(cond: *Io.Condition, mutex: *Io.Mutex) void { /// Same as `Io.Mutex.lockUncancelable` but avoids the VTable. pub fn mutexLock(m: *Io.Mutex) void { - const initial_state = m.state.cmpxchgWeak( + const initial_state = m.state.cmpxchgStrong( .unlocked, .locked_once, .acquire, diff --git a/lib/std/Progress.zig b/lib/std/Progress.zig @@ -450,7 +450,7 @@ pub const Node = struct { const ipc = @atomicLoad(Ipc, ipc_ptr, .monotonic); if (ipc.locked or ipc.valid) continue; const generation = ipc.generation +% 1; - if (@cmpxchgWeak( + if (@cmpxchgStrong( Ipc, ipc_ptr, ipc, @@ -1133,7 +1133,7 @@ fn serialize(io: Io, serialized_buffer: *Serialized.Buffer) !Serialized { const ipc_data = &serialized_buffer.ipc_data[ipc_index.slot]; state: switch (ipc_data.state) { .unused => { - if (@cmpxchgWeak( + if (@cmpxchgStrong( Ipc, ipc, .{ .locked = false, .valid = true, .generation = ipc_index.generation },