1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- #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);
- }
|