diff options
| author | Mara Bos <m-ou.se@m-ou.se> | 2024-03-19 15:00:09 +0100 |
|---|---|---|
| committer | Mara Bos <m-ou.se@m-ou.se> | 2024-03-19 15:27:11 +0100 |
| commit | eb966983f2814b80d6bb526b53557dd32b1621c0 (patch) | |
| tree | 931b2463fe8cdca7e4da071c6300a33b7ecee944 | |
| parent | 9f25a04498fbe30dcf6a9c764953704c333a0137 (diff) | |
| download | rust-eb966983f2814b80d6bb526b53557dd32b1621c0.tar.gz rust-eb966983f2814b80d6bb526b53557dd32b1621c0.zip | |
SeqCst->{Release,Acquire} in xous mutex.
No need for SeqCst. Release+Acquire is the right memory ordering for a mutex.
| -rw-r--r-- | library/std/src/sys/sync/mutex/xous.rs | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/library/std/src/sys/sync/mutex/xous.rs b/library/std/src/sys/sync/mutex/xous.rs index a8c9518ff0b..1426e48f8b7 100644 --- a/library/std/src/sys/sync/mutex/xous.rs +++ b/library/std/src/sys/sync/mutex/xous.rs @@ -1,6 +1,9 @@ use crate::os::xous::ffi::{blocking_scalar, do_yield}; use crate::os::xous::services::{ticktimer_server, TicktimerScalar}; -use crate::sync::atomic::{AtomicBool, AtomicUsize, Ordering::Relaxed, Ordering::SeqCst}; +use crate::sync::atomic::{ + AtomicBool, AtomicUsize, + Ordering::{Acquire, Relaxed, Release}, +}; pub struct Mutex { /// The "locked" value indicates how many threads are waiting on this @@ -68,7 +71,7 @@ impl Mutex { #[inline] pub unsafe fn unlock(&self) { - let prev = self.locked.fetch_sub(1, SeqCst); + let prev = self.locked.fetch_sub(1, Release); // If the previous value was 1, then this was a "fast path" unlock, so no // need to involve the Ticktimer server @@ -89,12 +92,12 @@ impl Mutex { #[inline] pub unsafe fn try_lock(&self) -> bool { - self.locked.compare_exchange(0, 1, SeqCst, SeqCst).is_ok() + self.locked.compare_exchange(0, 1, Acquire, Relaxed).is_ok() } #[inline] pub unsafe fn try_lock_or_poison(&self) -> bool { - self.locked.fetch_add(1, SeqCst) == 0 + self.locked.fetch_add(1, Acquire) == 0 } } |
