use crate::collector::RawCollectorImpl;
use crate::{ContextState, ShadowStack, CollectorRef};
use std::mem::ManuallyDrop;
use std::fmt::Debug;
#[cfg(feature = "sync")]
pub mod sync;
pub mod nosync;
pub unsafe trait CollectionManager<C>: self::sealed::Sealed
where C: RawCollectorImpl<Manager=Self, RawContext=Self::Context> {
type Context: RawContext<C>;
fn new() -> Self;
fn is_collecting(&self) -> bool;
fn should_trigger_collection(&self) -> bool;
unsafe fn freeze_context(&self, context: &Self::Context);
unsafe fn unfreeze_context(&self, context: &Self::Context);
fn prevent_collection<R>(collector: &C, func: impl FnOnce() -> R) -> R;
unsafe fn free_context(collector: &C, context: *mut Self::Context);
}
pub unsafe trait RawContext<C>: Debug + self::sealed::Sealed
where C: RawCollectorImpl<RawContext=Self> {
unsafe fn register_new(collector: &CollectorRef<C>) -> ManuallyDrop<Box<Self>>;
unsafe fn trigger_safepoint(&self);
#[inline]
unsafe fn assume_valid_shadow_stack(&self) -> &ShadowStack<C> {
match self.state() {
ContextState::Active => unreachable!("active context: {:?}", self),
ContextState::SafePoint { .. } | ContextState::Frozen { .. } => {},
}
&*self.shadow_stack_ptr()
}
fn shadow_stack_ptr(&self) -> *mut ShadowStack<C>;
unsafe fn collector(&self) -> &C;
fn state(&self) -> ContextState;
}
mod sealed {
pub trait Sealed {}
}