@@ -9,6 +9,8 @@ pub struct Mutex {
99 initialized : AtomicU8 ,
1010}
1111
12+ pub type MovableMutex = Mutex ;
13+
1214unsafe impl Send for Mutex { }
1315unsafe impl Sync for Mutex { }
1416
@@ -31,14 +33,14 @@ impl Mutex {
3133 #[ inline]
3234 unsafe fn atomic_init ( & self ) {
3335 loop {
34- match self . initialized . compare_and_swap ( UNINITIALIZED , INITIALIZING , SeqCst ) {
35- UNINITIALIZED => {
36+ match self . initialized . compare_exchange_weak ( UNINITIALIZED , INITIALIZING , SeqCst , SeqCst ) {
37+ Ok ( UNINITIALIZED ) => {
3638 * self . inner . get ( ) = xSemaphoreCreateMutex ( ) ;
3739 debug_assert ! ( !( * self . inner. get( ) ) . is_null( ) ) ;
3840 self . initialized . store ( INITIALIZED , SeqCst ) ;
3941 return ;
4042 }
41- INITIALIZED => return ,
43+ Err ( INITIALIZED ) => return ,
4244 _ => continue ,
4345 }
4446 }
@@ -67,14 +69,14 @@ impl Mutex {
6769 #[ inline]
6870 pub unsafe fn destroy ( & self ) {
6971 loop {
70- match self . initialized . compare_and_swap ( INITIALIZED , UNINITIALIZING , SeqCst ) {
71- INITIALIZED => {
72+ match self . initialized . compare_exchange_weak ( INITIALIZED , UNINITIALIZING , SeqCst , SeqCst ) {
73+ Ok ( INITIALIZED ) => {
7274 vSemaphoreDelete ( * self . inner . get ( ) ) ;
7375 * self . inner . get ( ) = ptr:: null_mut ( ) ;
7476 self . initialized . store ( UNINITIALIZED , SeqCst ) ;
7577 return ;
7678 }
77- UNINITIALIZED => return ,
79+ Err ( UNINITIALIZED ) => return ,
7880 _ => continue ,
7981 }
8082 }
@@ -111,14 +113,14 @@ impl ReentrantMutex {
111113 #[ inline]
112114 unsafe fn atomic_init ( & self ) {
113115 loop {
114- match self . initialized . compare_and_swap ( UNINITIALIZED , INITIALIZING , SeqCst ) {
115- UNINITIALIZED => {
116+ match self . initialized . compare_exchange_weak ( UNINITIALIZED , INITIALIZING , SeqCst , SeqCst ) {
117+ Ok ( UNINITIALIZED ) => {
116118 * self . inner . get ( ) = xSemaphoreCreateRecursiveMutex ( ) ;
117119 debug_assert ! ( !( * self . inner. get( ) ) . is_null( ) ) ;
118120 self . initialized . store ( INITIALIZED , SeqCst ) ;
119121 return ;
120122 }
121- INITIALIZED => return ,
123+ Err ( INITIALIZED ) => return ,
122124 _ => continue ,
123125 }
124126 }
@@ -145,14 +147,14 @@ impl ReentrantMutex {
145147
146148 pub unsafe fn destroy ( & self ) {
147149 loop {
148- match self . initialized . compare_and_swap ( INITIALIZED , UNINITIALIZING , SeqCst ) {
149- INITIALIZED => {
150+ match self . initialized . compare_exchange_weak ( INITIALIZED , UNINITIALIZING , SeqCst , SeqCst ) {
151+ Ok ( INITIALIZED ) => {
150152 vSemaphoreDelete ( * self . inner . get ( ) ) ;
151153 * self . inner . get ( ) = ptr:: null_mut ( ) ;
152154 self . initialized . store ( UNINITIALIZED , SeqCst ) ;
153155 return ;
154156 }
155- UNINITIALIZED => return ,
157+ Err ( UNINITIALIZED ) => return ,
156158 _ => continue ,
157159 }
158160 }
0 commit comments