use std::marker;
use super::{local, Shared};
#[must_use]
#[derive(Debug)]
pub struct Guard {
_marker: marker::PhantomData<*mut ()>, }
pub fn pin() -> Guard {
local::with_participant(|p| {
let entered = p.enter();
let g = Guard {
_marker: marker::PhantomData,
};
if entered && p.should_gc() {
p.try_collect(&g);
}
g
})
}
impl Guard {
pub unsafe fn unlinked<T>(&self, val: Shared<T>) {
local::with_participant(|p| p.reclaim(val.as_raw()))
}
pub fn migrate_garbage(&self) {
local::with_participant(|p| p.migrate_garbage())
}
}
impl Drop for Guard {
fn drop(&mut self) {
local::with_participant(|p| p.exit());
}
}