Skip to content

Commit 1c275b9

Browse files
authored
Merge pull request #3 from taiki-e/compare_and_swap
Replace deprecated compare_and_swap with compare_exchange
2 parents 5d18d15 + e039c44 commit 1c275b9

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/lib.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use std::cell::UnsafeCell;
44
use std::fmt;
55
use std::sync::atomic::AtomicUsize;
6-
use std::sync::atomic::Ordering::{Acquire, Release, AcqRel};
6+
use std::sync::atomic::Ordering::{AcqRel, Acquire, Release};
77
use std::task::Waker;
88

99
/// A synchronization primitive for task wakeup.
@@ -261,7 +261,11 @@ impl AtomicWaker {
261261
/// }
262262
/// ```
263263
pub fn register(&self, waker: &Waker) {
264-
match self.state.compare_and_swap(WAITING, REGISTERING, Acquire) {
264+
match self
265+
.state
266+
.compare_exchange(WAITING, REGISTERING, Acquire, Acquire)
267+
.unwrap_or_else(|x| x)
268+
{
265269
WAITING => {
266270
unsafe {
267271
// Locked acquired, update the waker cell
@@ -277,8 +281,9 @@ impl AtomicWaker {
277281
// nothing to acquire, only release. In case of concurrent
278282
// wakers, we need to acquire their releases, so success needs
279283
// to do both.
280-
let res = self.state.compare_exchange(
281-
REGISTERING, WAITING, AcqRel, Acquire);
284+
let res = self
285+
.state
286+
.compare_exchange(REGISTERING, WAITING, AcqRel, Acquire);
282287

283288
match res {
284289
Ok(_) => {
@@ -342,9 +347,7 @@ impl AtomicWaker {
342347
//
343348
// We just want to maintain memory safety. It is ok to drop the
344349
// call to `register`.
345-
debug_assert!(
346-
state == REGISTERING ||
347-
state == REGISTERING | WAKING);
350+
debug_assert!(state == REGISTERING || state == REGISTERING | WAKING);
348351
}
349352
}
350353
}
@@ -389,9 +392,8 @@ impl AtomicWaker {
389392
// not.
390393
//
391394
debug_assert!(
392-
state == REGISTERING ||
393-
state == REGISTERING | WAKING ||
394-
state == WAKING);
395+
state == REGISTERING || state == REGISTERING | WAKING || state == WAKING
396+
);
395397
None
396398
}
397399
}

0 commit comments

Comments
 (0)