1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use std::mem::MaybeUninit;
use crate::*;
#[repr(C, align(8))]
pub(crate) struct Entry<T> {
pub(crate) data: MaybeUninit<T>,
pub(crate) descr: *mut Entry<T>,
}
impl<T> Entry<T> {
pub(crate) const END_OF_FREELIST: *mut Self = std::ptr::null_mut();
pub(crate) const PINNED_SENTINEL: *mut Self = PINNED as *mut Self;
pub(crate) const REFERENCED_SENTINEL: *mut Self = REFERENCED as *mut Self;
pub(crate) const INITIALIZED_SENTINEL: *mut Self = INITIALIZED as *mut Self;
pub(crate) const UNINITIALIZED_SENTINEL: *mut Self = UNINITIALIZED as *mut Self;
pub fn is_allocated(&self) -> bool {
matches!(
self.descr as usize,
UNINITIALIZED | INITIALIZED | REFERENCED | PINNED
)
}
pub fn is_uninitialized(&self) -> bool {
matches!(self.descr as usize, UNINITIALIZED)
}
pub fn is_initialized(&self) -> bool {
matches!(self.descr as usize, INITIALIZED | REFERENCED | PINNED)
}
pub fn is_referenced(&self) -> bool {
matches!(self.descr as usize, REFERENCED | PINNED)
}
pub fn is_pinned(&self) -> bool {
matches!(self.descr as usize, PINNED)
}
}