11use crate :: os:: xous:: ffi:: { blocking_scalar, do_yield} ;
22use 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
58pub 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