use std::{cell, marker, mem};
use o3::{alloc, base::marker::ThreadBound};
use crate::driver::schedule::clock::timer::heap::{Core, Min};
#[repr(transparent)]
pub struct Store<P: Ord, R, Tag = ()> {
inner: cell::UnsafeCell<Core<P, R>>,
tag: marker::PhantomData<cell::Cell<Tag>>,
thread: marker::PhantomData<ThreadBound>,
}
impl<P: Ord, R, Tag> Store<P, R, Tag> {
pub fn try_new(cap: usize) -> Result<Self, alloc::Error> {
Ok(Self {
inner: cell::UnsafeCell::new(Core::try_new(cap)?),
tag: marker::PhantomData,
thread: marker::PhantomData,
})
}
pub unsafe fn loan<'id, T>(
&'id self,
op: impl for<'a> FnOnce(Min<'a, 'id, P, R, Tag>) -> T,
) -> T {
op(Min::new(
unsafe { &mut *self.inner.get() },
marker::PhantomData,
))
}
}
const _: () = {
assert!(mem::size_of::<Store<u128, u64>>() == 6 * mem::size_of::<usize>());
assert!(mem::align_of::<Store<u128, u64>>() == mem::align_of::<usize>());
};