1
1
use crate :: os:: xous:: ffi:: { blocking_scalar, do_yield} ;
2
2
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
+ } ;
4
7
5
8
pub struct Mutex {
6
9
/// The "locked" value indicates how many threads are waiting on this
@@ -68,7 +71,7 @@ impl Mutex {
68
71
69
72
#[ inline]
70
73
pub unsafe fn unlock ( & self ) {
71
- let prev = self . locked . fetch_sub ( 1 , SeqCst ) ;
74
+ let prev = self . locked . fetch_sub ( 1 , Release ) ;
72
75
73
76
// If the previous value was 1, then this was a "fast path" unlock, so no
74
77
// need to involve the Ticktimer server
@@ -89,12 +92,12 @@ impl Mutex {
89
92
90
93
#[ inline]
91
94
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 ( )
93
96
}
94
97
95
98
#[ inline]
96
99
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
98
101
}
99
102
}
100
103
0 commit comments