Skip to content

Commit

Permalink
Return bool from Guard::try_advance_global
Browse files Browse the repository at this point in the history
  • Loading branch information
marc0246 committed Jun 16, 2024
1 parent 7c2cc83 commit 2a44e6c
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/epoch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,13 +295,14 @@ impl Guard<'_> {
&self.local().global
}

/// Tries to advance the global epoch.
/// Tries to advance the global epoch. Returns `true` if the epoch was successfully advanced.
#[inline]
pub fn try_advance_global(&self) {
pub fn try_advance_global(&self) -> bool {
let local = self.local();
local.global().try_advance();
// This prevents us from trying to advance the global epoch in `LocalHandle::pin`.
local.pin_count.set(0);

local.global().try_advance()
}

#[inline]
Expand Down Expand Up @@ -461,7 +462,7 @@ impl Global {
}

#[inline(never)]
fn try_advance(&self) {
fn try_advance(&self) -> bool {
let global_epoch = self.epoch.load(Relaxed);

// Ensure that none of the loads of the local epochs can be ordered before the load of the
Expand All @@ -470,7 +471,7 @@ impl Global {

if !self.try_lock_local_list() {
// Another thread beat us to it.
return;
return false;
}

let mut head = self.local_list_head.get();
Expand All @@ -484,7 +485,7 @@ impl Global {
// SAFETY: We locked the local list above.
unsafe { self.unlock_local_list() };

return;
return false;
}

head = local.next.get();
Expand All @@ -504,6 +505,8 @@ impl Global {
// of all other participants from the previous epoch.
atomic::fence(Acquire);
self.epoch.store(new_epoch, Release);

true
}
}

Expand Down

0 comments on commit 2a44e6c

Please sign in to comment.