Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Commit

Permalink
Use fetch_update instead of open-coding the compare-exchange loop.
Browse files Browse the repository at this point in the history
  • Loading branch information
adamreichold committed May 18, 2024
1 parent 275d4db commit 2044350
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,21 +122,12 @@ where
last_next = unsafe { &mut (**last_next).next };
}

let mut old_top = self.0.load(Ordering::Relaxed);

loop {
*last_next = old_top;

match self.0.compare_exchange_weak(
old_top,
new_top,
Ordering::AcqRel,
Ordering::Relaxed,
) {
Ok(_) => break,
Err(top) => old_top = top,
}
}
self.0
.fetch_update(Ordering::AcqRel, Ordering::Relaxed, |old_top| {
*last_next = old_top;
Some(new_top)
})
.unwrap();
}

/// Collect the values into an iterator
Expand Down

0 comments on commit 2044350

Please sign in to comment.