Deallocate the given block
| 1149 | |
| 1150 | //! Deallocate the given block |
| 1151 | static void |
| 1152 | _memory_deallocate(void* p) { |
| 1153 | if (!p) |
| 1154 | return; |
| 1155 | |
| 1156 | //Grab the span (always at start of span, using 64KiB alignment) |
| 1157 | span_t* span = (void*)((uintptr_t)p & SPAN_MASK); |
| 1158 | int32_t heap_id = atomic_load32(&span->heap_id); |
| 1159 | heap_t* heap = _memory_thread_heap; |
| 1160 | //Check if block belongs to this heap or if deallocation should be deferred |
| 1161 | if (heap_id == heap->id) { |
| 1162 | if (span->size_class < SIZE_CLASS_COUNT) |
| 1163 | _memory_deallocate_to_heap(heap, span, p); |
| 1164 | else |
| 1165 | _memory_deallocate_large_to_heap(heap, span); |
| 1166 | } |
| 1167 | else if (heap_id > 0) { |
| 1168 | _memory_deallocate_defer(heap_id, p); |
| 1169 | } |
| 1170 | else { |
| 1171 | //Oversized allocation, page count is stored in next_span |
| 1172 | size_t num_pages = (size_t)span->next_span; |
| 1173 | _memory_unmap(span, num_pages); |
| 1174 | } |
| 1175 | } |
| 1176 | |
| 1177 | //! Reallocate the given block to the given size |
| 1178 | static void* |
no test coverage detected