Skip to content

Commit

Permalink
Moved use of MSRV-breaking method
Browse files Browse the repository at this point in the history
  • Loading branch information
zesterer committed Apr 25, 2023
1 parent 94cd9c5 commit 77754ce
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/mutex/ticket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,17 +243,27 @@ impl<T: ?Sized, R> TicketMutex<T, R> {
/// ```
#[inline(always)]
pub fn try_lock(&self) -> Option<TicketMutexGuard<T>> {
let ticket = self
.next_ticket
.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |ticket| {
if self.next_serving.load(Ordering::Acquire) == ticket {
Some(ticket + 1)
// TODO: Replace with `fetch_update` to avoid manual CAS when upgrading MSRV
let ticket = {
let mut prev = self.next_ticket.load(Ordering::SeqCst);
loop {
if self.next_serving.load(Ordering::Acquire) == prev {
match self.next_ticket.compare_exchange_weak(
prev,
prev + 1,
Ordering::SeqCst,
Ordering::SeqCst,
) {
Ok(x) => break Some(x),
Err(next_prev) => prev = next_prev,
}
} else {
None
break None;
}
});
}
};

ticket.ok().map(|ticket| TicketMutexGuard {
ticket.map(|ticket| TicketMutexGuard {
next_serving: &self.next_serving,
ticket,
// Safety
Expand Down

0 comments on commit 77754ce

Please sign in to comment.