authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-03-11 01:56:56+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-03-11 01:56:56+01:00
log5d9660972d4b2f1ed575978e8543c88e1392f6b5
treea7090c98163834489a27eed925467718463a5c1e
parentbd5dc75068dcfb3dcd6b8197ee5d941cacb15cb9
parentd70bd0b37eafb82e3020f163ebcbaa2c13791e75

Merge pull request 'fix: use cmpxchgStrong in `Io.Mutex`' (#31441) from GasInfinity/zig:io-mutex-cmpxchg-strong into master

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31441 Reviewed-by: Andrew Kelley <andrew@ziglang.org>

3 files changed, 4 insertions(+), 6 deletions(-)

lib/std/Io.zig+3-3
......@@ -1577,11 +1577,11 @@ pub const Mutex = extern struct {
15771577 };
15781578
15791579 pub fn tryLock(m: *Mutex) bool {
1580 return m.state.cmpxchgWeak(.unlocked, .locked_once, .acquire, .monotonic) == null;
1580 return m.state.cmpxchgStrong(.unlocked, .locked_once, .acquire, .monotonic) == null;
15811581 }
15821582
15831583 pub fn lock(m: *Mutex, io: Io) Cancelable!void {
1584 const initial_state = m.state.cmpxchgWeak(
1584 const initial_state = m.state.cmpxchgStrong(
15851585 .unlocked,
15861586 .locked_once,
15871587 .acquire,
......@@ -1602,7 +1602,7 @@ pub const Mutex = extern struct {
16021602 ///
16031603 /// For a description of cancelation and cancelation points, see `Future.cancel`.
16041604 pub fn lockUncancelable(m: *Mutex, io: Io) void {
1605 const initial_state = m.state.cmpxchgWeak(
1605 const initial_state = m.state.cmpxchgStrong(
16061606 .unlocked,
16071607 .locked_once,
16081608 .acquire,
lib/std/Io/RwLock.zig-2
......@@ -114,8 +114,6 @@ test "internal state" {
114114}
115115
116116test "smoke test" {
117 if (builtin.target.cpu.arch.isAARCH64()) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/31393
118
119117 const io = testing.io;
120118
121119 var rl: Io.RwLock = .init;
lib/std/atomic.zig+1-1
......@@ -509,7 +509,7 @@ pub const Mutex = enum(u8) {
509509 locked,
510510
511511 pub fn tryLock(m: *Mutex) bool {
512 return @cmpxchgWeak(Mutex, m, .unlocked, .locked, .acquire, .monotonic) == null;
512 return @cmpxchgStrong(Mutex, m, .unlocked, .locked, .acquire, .monotonic) == null;
513513 }
514514
515515 pub fn unlock(m: *Mutex) void {