#include "dmmlib.h" #include "other.h" #ifdef HAVE_LOCKS #include "posix_lock.h" #endif /* HAVE_LOCKS */ #include "block_header.h" void custom_ahfree(allocator_t *allocator, heap_t* heap, void *ptr) { size_t size; int heap_id, fixed_list_id, i; maptable_node_t *current_maptable_node; if(allocator == NULL) { allocator = &systemallocator; } if(heap == NULL) { heap_id = map_thread_heap(); heap = &allocator->heaps[heap_id]; } size = get_size(ptr); #ifdef HAVE_LOCKS posix_lock(heap); #endif /* HAVE_LOCKS */ remove_block(ptr, heap->used_blocks_head); fixed_list_id = map_size_to_list(heap, size); if(fixed_list_id != -1) { current_maptable_node = heap->maptable_head; if(fixed_list_id == 0) { set_next(ptr, current_maptable_node->fixed_list_head); current_maptable_node->fixed_list_head = ptr; } else { for(i = 1; i < fixed_list_id; i++) { current_maptable_node = current_maptable_node->next; } set_next(ptr, current_maptable_node->fixed_list_head); current_maptable_node->fixed_list_head = ptr; } } else { // put it in the free list set_next(ptr, heap->free_list_head); heap->free_list_head = ptr; } // Begin of Stats heap->dmm_stats.live_objects -= 1; heap->dmm_stats.num_free += 1; // End of Stats #ifdef HAVE_LOCKS posix_unlock(heap); #endif /* HAVE_LOCKS */ } void custom_free(void *ptr) { custom_ahfree(NULL, NULL, ptr); }