fix: use cmpxchgStrong in Io.Mutex

* `cmpxchgWeak` can fail spuriously on LL/SC architectures
and `tryLock` would invalidly return false in those cases.
This commit is contained in:
GasInfinity
2026-03-10 09:17:42 +01:00
parent cfe5c88ad6
commit 048e38624e
+3 -3
View File
@@ -1577,11 +1577,11 @@ pub const Mutex = extern struct {
}; };
pub fn tryLock(m: *Mutex) bool { pub fn tryLock(m: *Mutex) bool {
return m.state.cmpxchgWeak(.unlocked, .locked_once, .acquire, .monotonic) == null; return m.state.cmpxchgStrong(.unlocked, .locked_once, .acquire, .monotonic) == null;
} }
pub fn lock(m: *Mutex, io: Io) Cancelable!void { pub fn lock(m: *Mutex, io: Io) Cancelable!void {
const initial_state = m.state.cmpxchgWeak( const initial_state = m.state.cmpxchgStrong(
.unlocked, .unlocked,
.locked_once, .locked_once,
.acquire, .acquire,
@@ -1602,7 +1602,7 @@ pub const Mutex = extern struct {
/// ///
/// For a description of cancelation and cancelation points, see `Future.cancel`. /// For a description of cancelation and cancelation points, see `Future.cancel`.
pub fn lockUncancelable(m: *Mutex, io: Io) void { pub fn lockUncancelable(m: *Mutex, io: Io) void {
const initial_state = m.state.cmpxchgWeak( const initial_state = m.state.cmpxchgStrong(
.unlocked, .unlocked,
.locked_once, .locked_once,
.acquire, .acquire,