use crate::LocalAllocatorSelector;
use crate::per_cpu;
use core::ptr::NonNull;
use mnemosyne_arena::HasSegmentPool;
use mnemosyne_core::types::{Block, Page, Segment};
#[cold]
#[inline(never)]
pub(super) unsafe fn thread_free_cold<B: HasSegmentPool + LocalAllocatorSelector<B>>(
ptr: *mut u8,
page: *mut Page,
block: *mut Block,
) {
let encrypted = unsafe { Segment::free_list_encrypted(Page::parent_segment_of(page)) };
if B::ENABLE_CPU_CACHE
&& per_cpu::try_free_cpu(ptr, unsafe { (*page).size_class } as usize, encrypted)
{
#[cfg(feature = "dealloc-probe")]
crate::dealloc_counters::record(crate::dealloc_counters::DeallocPath::ColdOrRecursing);
return;
}
unsafe {
(*page)
.thread_free
.push_dynamic(NonNull::new_unchecked(block), encrypted);
}
#[cfg(feature = "dealloc-probe")]
crate::dealloc_counters::record(crate::dealloc_counters::DeallocPath::ColdOrRecursing);
}