From ffd46f75cac401b6c2d6ab444d8ebff11d1d04ca Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Thu, 31 Dec 2020 18:49:53 +0900 Subject: [PATCH] Replace deprecated compare_and_swap with compare_exchange --- src/sync/rwlock.rs | 13 ++++++++++--- src/task/task_local.rs | 6 +++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/sync/rwlock.rs b/src/sync/rwlock.rs index 08d8ed84..89c043f4 100644 --- a/src/sync/rwlock.rs +++ b/src/sync/rwlock.rs @@ -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; @@ -301,7 +301,11 @@ impl RwLock { /// # }) /// ``` pub fn try_write(&self) -> Option> { - 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 @@ -318,7 +322,10 @@ impl RwLock { /// 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() } diff --git a/src/task/task_local.rs b/src/task/task_local.rs index 4e2ba838..1661c0bb 100644 --- a/src/task/task_local.rs +++ b/src/task/task_local.rs @@ -124,9 +124,9 @@ impl LocalKey { 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, } }