crate::ix!();
#[derive(Getters)]
#[SCOPED_LOCKABLE]
pub struct EpochGuard {
epoch: Rc<RefCell<Epoch>>,
}
impl EpochGuard {
#[EXCLUSIVE_LOCK_FUNCTION(epoch)]
pub fn new(epoch: Rc<RefCell<Epoch>>) -> Self {
{
let ep_ref = epoch.borrow();
assert!(
!ep_ref.guarded(),
"attempted to create nested EpochGuard"
);
}
{
let mut ep_mut = epoch.borrow_mut();
ep_mut.increment_epoch();
ep_mut.set_guarded(true);
}
trace!(target: "epoch", "EpochGuard created");
Self { epoch }
}
}
impl Drop for EpochGuard {
#[UNLOCK_FUNCTION]
fn drop(&mut self) {
let mut ep = self.epoch.borrow_mut();
assert!(
ep.guarded(),
"EpochGuard dropped while not guarded"
);
ep.increment_epoch(); ep.set_guarded(false); trace!(target: "epoch", "EpochGuard dropped");
}
}