Replace deprecated compare_and_swap with compare_exchange
This commit is contained in:
parent
5d18d15e1d
commit
e039c44a53
22
src/lib.rs
22
src/lib.rs
|
@ -3,7 +3,7 @@
|
|||
use std::cell::UnsafeCell;
|
||||
use std::fmt;
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
use std::sync::atomic::Ordering::{Acquire, Release, AcqRel};
|
||||
use std::sync::atomic::Ordering::{AcqRel, Acquire, Release};
|
||||
use std::task::Waker;
|
||||
|
||||
/// A synchronization primitive for task wakeup.
|
||||
|
@ -261,7 +261,11 @@ impl AtomicWaker {
|
|||
/// }
|
||||
/// ```
|
||||
pub fn register(&self, waker: &Waker) {
|
||||
match self.state.compare_and_swap(WAITING, REGISTERING, Acquire) {
|
||||
match self
|
||||
.state
|
||||
.compare_exchange(WAITING, REGISTERING, Acquire, Acquire)
|
||||
.unwrap_or_else(|x| x)
|
||||
{
|
||||
WAITING => {
|
||||
unsafe {
|
||||
// Locked acquired, update the waker cell
|
||||
|
@ -277,8 +281,9 @@ impl AtomicWaker {
|
|||
// nothing to acquire, only release. In case of concurrent
|
||||
// wakers, we need to acquire their releases, so success needs
|
||||
// to do both.
|
||||
let res = self.state.compare_exchange(
|
||||
REGISTERING, WAITING, AcqRel, Acquire);
|
||||
let res = self
|
||||
.state
|
||||
.compare_exchange(REGISTERING, WAITING, AcqRel, Acquire);
|
||||
|
||||
match res {
|
||||
Ok(_) => {
|
||||
|
@ -342,9 +347,7 @@ impl AtomicWaker {
|
|||
//
|
||||
// We just want to maintain memory safety. It is ok to drop the
|
||||
// call to `register`.
|
||||
debug_assert!(
|
||||
state == REGISTERING ||
|
||||
state == REGISTERING | WAKING);
|
||||
debug_assert!(state == REGISTERING || state == REGISTERING | WAKING);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -389,9 +392,8 @@ impl AtomicWaker {
|
|||
// not.
|
||||
//
|
||||
debug_assert!(
|
||||
state == REGISTERING ||
|
||||
state == REGISTERING | WAKING ||
|
||||
state == WAKING);
|
||||
state == REGISTERING || state == REGISTERING | WAKING || state == WAKING
|
||||
);
|
||||
None
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue