use std::{cell, ops};
use crate::buffer::pool::owners::Free;
mod shape;
pub(in crate::buffer::pool) use shape::Shape;
#[repr(C, align(8))]
pub(in crate::buffer::pool) struct Header<K = super::Plain> {
pub(super) balance: cell::Cell<i64>,
pub(super) free: Free,
shape: super::Shape<K>,
}
impl<K> Header<K> {
pub(super) const fn new(shape: super::Shape<K>) -> Self {
let slots = shape.slots();
Self {
balance: cell::Cell::new(slots as i64),
free: Free::new(slots),
shape,
}
}
pub(super) fn is_detached(&self) -> bool {
self.balance.get() < 0
}
}
impl<K> ops::Deref for Header<K> {
type Target = super::Shape<K>;
fn deref(&self) -> &Self::Target {
&self.shape
}
}
const _: () = {
assert!(size_of::<Header>() == 32);
assert!(size_of::<Header<super::Resident<'static>>>() == 32);
assert!(align_of::<Header>() == 8);
assert!(align_of::<Header>() >= align_of::<super::raw::Slot>());
assert!(align_of::<Header>() >= align_of::<super::raw::Slot<super::Resident<'static>>>());
assert!(align_of::<Header>() >= align_of::<super::Accounts>());
assert!(
size_of::<super::raw::Slot<super::Resident<'static>>>()
.is_multiple_of(align_of::<super::Accounts>())
);
assert!(size_of::<super::Accounts>().is_multiple_of(align_of::<super::Account>()));
};