Skip to content

Commit

Permalink
Remove usage of AtomicUsize::compare_exchange
Browse files Browse the repository at this point in the history
It is going to be deprecated in 1.50, but it's already producing
warnings on nightly.
  • Loading branch information
Thomasdezeeuw committed Jan 8, 2021
1 parent c10d1e5 commit 16ecfbe
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,12 +324,18 @@ impl AtomicUsize {
}

#[cfg(atomic_cas)]
fn compare_and_swap(&self, current: usize, new: usize, _order: Ordering) -> usize {
fn compare_exchange(
&self,
current: usize,
new: usize,
_success: Ordering,
_failure: Ordering,
) -> Result<usize, usize> {
let prev = self.v.get();
if current == prev {
self.v.set(new);
}
prev
Ok(prev)
}
}

Expand Down Expand Up @@ -1338,7 +1344,15 @@ fn set_logger_inner<F>(make_logger: F) -> Result<(), SetLoggerError>
where
F: FnOnce() -> &'static dyn Log,
{
match STATE.compare_and_swap(UNINITIALIZED, INITIALIZING, Ordering::SeqCst) {
let old_state = match STATE.compare_exchange(
UNINITIALIZED,
INITIALIZING,
Ordering::SeqCst,
Ordering::SeqCst,
) {
Ok(s) | Err(s) => s,
};
match old_state {
UNINITIALIZED => {
unsafe {
LOGGER = make_logger();
Expand Down

0 comments on commit 16ecfbe

Please sign in to comment.