Use standard parity and saturating generation operations
This commit is contained in:
@@ -15,7 +15,7 @@ impl Lifetime {
|
||||
/// Even generations are idle; odd generations belong to one live gesture.
|
||||
pub(super) fn idle(&self) -> Option<u64> {
|
||||
let generation = self.0.load(Ordering::SeqCst);
|
||||
(generation % 2 == 0).then_some(generation)
|
||||
generation.is_multiple_of(2).then_some(generation)
|
||||
}
|
||||
|
||||
/// Retire an idle packet at a native input boundary (including the
|
||||
@@ -23,7 +23,7 @@ impl Lifetime {
|
||||
pub(super) fn revoke_idle(&self) {
|
||||
if let Some(generation) = self.idle() {
|
||||
// Keep overflow terminal and unavailable rather than reusing zero.
|
||||
let next = generation.checked_add(2).unwrap_or(u64::MAX);
|
||||
let next = generation.saturating_add(2);
|
||||
let _ = self
|
||||
.0
|
||||
.compare_exchange(generation, next, Ordering::SeqCst, Ordering::SeqCst);
|
||||
|
||||
Reference in New Issue
Block a user