| 90 | } |
| 91 | |
| 92 | unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) |
| 93 | { |
| 94 | let mut allocator = self.lock(); |
| 95 | match lsidx(&layout) |
| 96 | { |
| 97 | Some(index) => |
| 98 | { |
| 99 | let new_node = ListNode |
| 100 | { |
| 101 | next: allocator.listheads[index].take(), |
| 102 | }; |
| 103 | |
| 104 | // Verify that the block has a size and an alignment. |
| 105 | assert!(mem::size_of::<ListNode>() <= BLKSIZES[index]); |
| 106 | assert!(mem::align_of::<ListNode>() <= BLKSIZES[index]); |
| 107 | let new_node_ptr = ptr as *mut ListNode; |
| 108 | new_node_ptr.write(new_node); |
| 109 | allocator.listheads[index] = Some(&mut *new_node_ptr); |
| 110 | } |
| 111 | None => |
| 112 | { |
| 113 | let ptr = NonNull::new(ptr).unwrap(); |
| 114 | allocator.fballoc.deallocate(ptr, layout); |
| 115 | } |
| 116 | } |
| 117 | } |
| 118 | } |