#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum Point {
ReaderAfterRoot,
ReaderAfterChildVersion,
CursorSeek,
WriterAfterVersion,
WriterBeforeUpgrade,
}
#[cfg(not(artmap_hooks))]
#[inline(always)]
pub(crate) fn pause(_point: Point) {}
#[cfg(artmap_hooks)]
mod imp {
use super::Point;
use std::cell::RefCell;
type Hook = Box<dyn FnMut(Point)>;
thread_local! {
static HOOK: RefCell<Option<Hook>> = const { RefCell::new(None) };
}
pub fn pause(point: Point) {
let hook = HOOK.with(|h| h.borrow_mut().take());
if let Some(mut f) = hook {
f(point);
HOOK.with(|h| {
let mut slot = h.borrow_mut();
if slot.is_none() {
*slot = Some(f);
}
});
}
}
pub fn set(f: impl FnMut(Point) + 'static) {
HOOK.with(|h| *h.borrow_mut() = Some(Box::new(f)));
}
pub fn clear() {
HOOK.with(|h| *h.borrow_mut() = None);
}
}
#[cfg(artmap_hooks)]
pub use imp::{clear, pause, set};