| 35 | |
| 36 | unsafe impl GlobalAlloc for FreeListAlloc { |
| 37 | unsafe fn alloc(&self, layout: Layout) -> *mut u8 { |
| 38 | if !INIT.load(Ordering::Relaxed) { |
| 39 | unsafe { (*HEAP.0.get()).init(POOL.0.get() as *mut u8, POOL_SIZE); } |
| 40 | INIT.store(true, Ordering::Relaxed); |
| 41 | } |
| 42 | unsafe { |
| 43 | (*HEAP.0.get()) |
| 44 | .allocate_first_fit(layout) |
| 45 | .map_or(core::ptr::null_mut(), |p| p.as_ptr()) |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) { |
| 50 | unsafe { (*HEAP.0.get()).deallocate(NonNull::new_unchecked(ptr), layout); } |