use std::sync::atomic::{AtomicU64, Ordering};
static NEXT_CLAIM_EPOCH: AtomicU64 = AtomicU64::new(1);
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(super) struct BatchIdentity {
pub(super) claim_epoch: u64,
pub(super) batch_seq: u64,
}
impl BatchIdentity {
pub(super) fn new_claim() -> Option<Self> {
NEXT_CLAIM_EPOCH
.fetch_update(Ordering::AcqRel, Ordering::Acquire, |value| {
value.checked_add(1)
})
.ok()
.map(|claim_epoch| Self {
claim_epoch,
batch_seq: 0,
})
}
pub(super) fn advance(&mut self) -> Option<Self> {
self.batch_seq = self.batch_seq.checked_add(1)?;
Some(*self)
}
}