Skip to content

Commit ffd46f7

Browse files
committed
Replace deprecated compare_and_swap with compare_exchange
1 parent 5484f5b commit ffd46f7

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/sync/rwlock.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use std::cell::UnsafeCell;
22
use std::fmt;
3+
use std::future::Future;
34
use std::isize;
45
use std::ops::{Deref, DerefMut};
56
use std::pin::Pin;
67
use std::process;
7-
use std::future::Future;
88
use std::sync::atomic::{AtomicUsize, Ordering};
99

1010
use crate::sync::WakerSet;
@@ -301,7 +301,11 @@ impl<T: ?Sized> RwLock<T> {
301301
/// # })
302302
/// ```
303303
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, Ordering::SeqCst)
307+
.is_ok()
308+
{
305309
Some(RwLockWriteGuard(self))
306310
} else {
307311
None
@@ -318,7 +322,10 @@ impl<T: ?Sized> RwLock<T> {
318322
/// let lock = RwLock::new(10);
319323
/// assert_eq!(lock.into_inner(), 10);
320324
/// ```
321-
pub fn into_inner(self) -> T where T: Sized {
325+
pub fn into_inner(self) -> T
326+
where
327+
T: Sized,
328+
{
322329
self.value.into_inner()
323330
}
324331

src/task/task_local.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ impl<T: Send + 'static> LocalKey<T> {
124124
std::process::abort();
125125
}
126126

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, Ordering::Acquire) {
128+
Ok(_) => counter,
129+
Err(k) => k,
130130
}
131131
}
132132

0 commit comments

Comments
 (0)