mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-04-27 19:09:47 +03:00
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:
+3
-3
@@ -1577,11 +1577,11 @@ pub const Mutex = extern struct {
|
||||
};
|
||||
|
||||
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 {
|
||||
const initial_state = m.state.cmpxchgWeak(
|
||||
const initial_state = m.state.cmpxchgStrong(
|
||||
.unlocked,
|
||||
.locked_once,
|
||||
.acquire,
|
||||
@@ -1602,7 +1602,7 @@ pub const Mutex = extern struct {
|
||||
///
|
||||
/// For a description of cancelation and cancelation points, see `Future.cancel`.
|
||||
pub fn lockUncancelable(m: *Mutex, io: Io) void {
|
||||
const initial_state = m.state.cmpxchgWeak(
|
||||
const initial_state = m.state.cmpxchgStrong(
|
||||
.unlocked,
|
||||
.locked_once,
|
||||
.acquire,
|
||||
|
||||
Reference in New Issue
Block a user