Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit eb96698

Browse files
committed
SeqCst->{Release,Acquire} in xous mutex.
No need for SeqCst. Release+Acquire is the right memory ordering for a mutex.
1 parent 9f25a04 commit eb96698

File tree

1 file changed

+7
-4
lines changed
  • library/std/src/sys/sync/mutex

1 file changed

+7
-4
lines changed

library/std/src/sys/sync/mutex/xous.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use crate::os::xous::ffi::{blocking_scalar, do_yield};
22
use crate::os::xous::services::{ticktimer_server, TicktimerScalar};
3-
use crate::sync::atomic::{AtomicBool, AtomicUsize, Ordering::Relaxed, Ordering::SeqCst};
3+
use crate::sync::atomic::{
4+
AtomicBool, AtomicUsize,
5+
Ordering::{Acquire, Relaxed, Release},
6+
};
47

58
pub struct Mutex {
69
/// The "locked" value indicates how many threads are waiting on this
@@ -68,7 +71,7 @@ impl Mutex {
6871

6972
#[inline]
7073
pub unsafe fn unlock(&self) {
71-
let prev = self.locked.fetch_sub(1, SeqCst);
74+
let prev = self.locked.fetch_sub(1, Release);
7275

7376
// If the previous value was 1, then this was a "fast path" unlock, so no
7477
// need to involve the Ticktimer server
@@ -89,12 +92,12 @@ impl Mutex {
8992

9093
#[inline]
9194
pub unsafe fn try_lock(&self) -> bool {
92-
self.locked.compare_exchange(0, 1, SeqCst, SeqCst).is_ok()
95+
self.locked.compare_exchange(0, 1, Acquire, Relaxed).is_ok()
9396
}
9497

9598
#[inline]
9699
pub unsafe fn try_lock_or_poison(&self) -> bool {
97-
self.locked.fetch_add(1, SeqCst) == 0
100+
self.locked.fetch_add(1, Acquire) == 0
98101
}
99102
}
100103

0 commit comments

Comments
 (0)