Have a new() method

This commit is contained in:
Gwilym Kuiper 2021-08-16 21:07:25 +01:00
parent 2bacbf35dc
commit 22c6efa5fa

View file

@ -16,6 +16,14 @@ struct BumpAllocator {
current_ptr: Mutex<*mut u8>, current_ptr: Mutex<*mut u8>,
} }
impl BumpAllocator {
pub const fn new() -> Self {
Self {
current_ptr: Mutex::new(core::ptr::null_mut())
}
}
}
impl BumpAllocator { impl BumpAllocator {
fn alloc_safe(&self, layout: Layout) -> *mut u8 { fn alloc_safe(&self, layout: Layout) -> *mut u8 {
let mut current_ptr = self.current_ptr.lock(); let mut current_ptr = self.current_ptr.lock();
@ -56,9 +64,7 @@ fn alloc_error(layout: Layout) -> ! {
} }
#[global_allocator] #[global_allocator]
static GLOBAL_ALLOC: BumpAllocator = BumpAllocator { static GLOBAL_ALLOC: BumpAllocator = BumpAllocator::new();
current_ptr: Mutex::new(core::ptr::null_mut()),
};
#[cfg(test)] #[cfg(test)]
mod test { mod test {