File tree 2 files changed +13
-6
lines changed
2 files changed +13
-6
lines changed Original file line number Diff line number Diff line change 1
1
use std:: cell:: UnsafeCell ;
2
2
use std:: fmt;
3
+ use std:: future:: Future ;
3
4
use std:: isize;
4
5
use std:: ops:: { Deref , DerefMut } ;
5
6
use std:: pin:: Pin ;
6
7
use std:: process;
7
- use std:: future:: Future ;
8
8
use std:: sync:: atomic:: { AtomicUsize , Ordering } ;
9
9
10
10
use crate :: sync:: WakerSet ;
@@ -301,7 +301,11 @@ impl<T: ?Sized> RwLock<T> {
301
301
/// # })
302
302
/// ```
303
303
pub fn try_write ( & self ) -> Option < RwLockWriteGuard < ' _ , T > > {
304
- if self . state . compare_and_swap ( 0 , WRITE_LOCK , Ordering :: SeqCst ) == 0 {
304
+ if self
305
+ . state
306
+ . compare_exchange ( 0 , WRITE_LOCK , Ordering :: SeqCst )
307
+ . is_ok ( )
308
+ {
305
309
Some ( RwLockWriteGuard ( self ) )
306
310
} else {
307
311
None
@@ -318,7 +322,10 @@ impl<T: ?Sized> RwLock<T> {
318
322
/// let lock = RwLock::new(10);
319
323
/// assert_eq!(lock.into_inner(), 10);
320
324
/// ```
321
- pub fn into_inner ( self ) -> T where T : Sized {
325
+ pub fn into_inner ( self ) -> T
326
+ where
327
+ T : Sized ,
328
+ {
322
329
self . value . into_inner ( )
323
330
}
324
331
Original file line number Diff line number Diff line change @@ -124,9 +124,9 @@ impl<T: Send + 'static> LocalKey<T> {
124
124
std:: process:: abort ( ) ;
125
125
}
126
126
127
- match key. compare_and_swap ( 0 , counter, Ordering :: AcqRel ) {
128
- 0 => counter,
129
- k => k,
127
+ match key. compare_exchange ( 0 , counter, Ordering :: AcqRel ) {
128
+ Ok ( _ ) => counter,
129
+ Err ( k ) => k,
130
130
}
131
131
}
132
132
You can’t perform that action at this time.
0 commit comments