Ioannis Koutras 13 rokov pred
rodič
commit
e8a8a94d59
2 zmenil súbory, kde vykonal 8 pridanie a 3 odobranie
  1. 3 2
      src/coalesce.c
  2. 5 1
      src/custom_free.c

+ 3 - 2
src/coalesce.c

@@ -15,6 +15,8 @@ void * coalesce(void *ptr, heap_t *heap) {
     }
 
     // Try to coalesce with the previous memory block
+    // FIXME What happens if we have multiple heaps and we don't know the
+    // owner of the blocks?
     if(is_previous_free(ptr)) {
         prev = get_previous(ptr);
 
@@ -25,8 +27,7 @@ void * coalesce(void *ptr, heap_t *heap) {
             current_maptable_node = heap->maptable_head;
             if(fixed_list_id != 0) {
                 for(i = 1; i < fixed_list_id; i++) {
-                    current_maptable_node =
-                        current_maptable_node->next;
+                    current_maptable_node = current_maptable_node->next;
                 }
             }
             remove_block(ptr, current_maptable_node->fixed_list_head);

+ 5 - 1
src/custom_free.c

@@ -16,7 +16,7 @@ void custom_ahfree(allocator_t *allocator, heap_t* heap, void *ptr) {
     if(allocator == NULL) {
         allocator = &systemallocator;
     }
-   
+
     if(heap == NULL) {
         heap_id = map_thread_heap();
         heap = &allocator->heaps[heap_id];
@@ -31,6 +31,10 @@ void custom_ahfree(allocator_t *allocator, heap_t* heap, void *ptr) {
 
     remove_block(ptr, heap->used_blocks_head);
 
+#ifdef WITH_COALESCING
+    ptr = coalesce(heap, ptr); 
+#endif /* WITH_COALESCING */
+
     // Check if the block could be put in a fixed list
     fixed_list_id = map_size_to_list(heap, size);