Skip to content

Commit

Permalink
Merge pull request #439 from Thomasdezeeuw/remove_compare_exchange
Browse files Browse the repository at this point in the history
Remove usage of AtomicUsize::compare_exchange
  • Loading branch information
KodrAus authored Jan 9, 2021
2 parents c10d1e5 + 16ecfbe commit c9ab9d4
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 c9ab9d4

Please sign in to comment.