Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace deprecated compare_and_swap with compare_exchange #927

Merged
merged 1 commit into from
Jan 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/sync/rwlock.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::cell::UnsafeCell;
use std::fmt;
use std::future::Future;
use std::isize;
use std::ops::{Deref, DerefMut};
use std::pin::Pin;
use std::process;
use std::future::Future;
use std::sync::atomic::{AtomicUsize, Ordering};

use crate::sync::WakerSet;
Expand Down Expand Up @@ -301,7 +301,11 @@ impl<T: ?Sized> RwLock<T> {
/// # })
/// ```
pub fn try_write(&self) -> Option<RwLockWriteGuard<'_, T>> {
if self.state.compare_and_swap(0, WRITE_LOCK, Ordering::SeqCst) == 0 {
if self
.state
.compare_exchange(0, WRITE_LOCK, Ordering::SeqCst, Ordering::SeqCst)
.is_ok()
{
Some(RwLockWriteGuard(self))
} else {
None
Expand All @@ -318,7 +322,10 @@ impl<T: ?Sized> RwLock<T> {
/// let lock = RwLock::new(10);
/// assert_eq!(lock.into_inner(), 10);
/// ```
pub fn into_inner(self) -> T where T: Sized {
pub fn into_inner(self) -> T
where
T: Sized,
{
self.value.into_inner()
}

Expand Down
6 changes: 3 additions & 3 deletions src/task/task_local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ impl<T: Send + 'static> LocalKey<T> {
std::process::abort();
}

match key.compare_and_swap(0, counter, Ordering::AcqRel) {
0 => counter,
k => k,
match key.compare_exchange(0, counter, Ordering::AcqRel, Ordering::Acquire) {
Ok(_) => counter,
Err(k) => k,
}
}

Expand Down