瀏覽代碼

Include heap as an argument in remove_block() in case hops are counted.

Ioannis Koutras 13 年之前
父節點
當前提交
0cc10051ee
共有 4 個文件被更改,包括 32 次插入0 次删除
  1. 12 0
      private-include/linked_lists/linked_lists.h
  2. 4 0
      src/coalesce.c
  3. 4 0
      src/custom_free.c
  4. 12 0
      src/linked_lists/linked_lists.c

+ 12 - 0
private-include/linked_lists/linked_lists.h

@@ -100,6 +100,17 @@ void * get_previous(void *ptr);
  */
 void push_block(void **block, void **starting_node);
 
+
+#ifdef COUNT_HOPS
+/**
+ * Removes a memory block from a linked list of memory blocks.
+ *
+ * \param *heap A pointer to the heap structure which contains the block.
+ * \param **block A pointer to the block to be removed.
+ * \param **starting_node A pointer to the starting memory block of the list.
+ */
+void remove_block(heap_t *heap, void **block, void **starting_node);
+#else
 /**
  * Removes a memory block from a linked list of memory blocks.
  *
@@ -107,6 +118,7 @@ void push_block(void **block, void **starting_node);
  * \param **starting_node A pointer to the starting memory block of the list.
  */
 void remove_block(void **block, void **starting_node);
+#endif /* COUNT_HOPS */
 
 /**
  * Removes a memory block from any of the linked lists of free memory blocks.

+ 4 - 0
src/coalesce.c

@@ -40,7 +40,11 @@ void * coalesce(allocator_t *allocator, heap_t *heap, void *ptr, size_t size) {
                 current_maptable_node = current_maptable_node->next;
             }
         }
+#ifdef COUNT_HOPS
+        remove_block(heap, &ptr, &current_maptable_node->fixed_list_head);
+#else
         remove_block(&ptr, &current_maptable_node->fixed_list_head);
+#endif /* COUNT_HOPS */
     }
 #endif /* WITH_FIXED_LISTS */
 

+ 4 - 0
src/custom_free.c

@@ -69,7 +69,11 @@ void custom_ahfree(allocator_t *allocator, heap_t* heap, void *ptr) {
 #endif /* COUNT_HOPS */
 
 #ifdef FUTURE_FEATURES
+#ifdef COUNT_HOPS
+    remove_block(heap, &ptr, &heap->used_blocks_head);
+#else
     remove_block(&ptr, &heap->used_blocks_head);
+#endif /* COUNT_HOPS */
 #endif /* FUTURE_FEATURES */
 
 #ifdef WITH_STATS

+ 12 - 0
src/linked_lists/linked_lists.c

@@ -57,7 +57,11 @@ void push_block(void **block, void **starting_node) {
 }
 
 #ifdef BLOCKS_IN_SLL
+#ifdef COUNT_HOPS
+void remove_block(heap_t *heap, void **block, void **starting_node) {
+#else
 void remove_block(void **block, void **starting_node) {
+#endif /* COUNT_HOPS */
 
     void *current_node, *previous_node;
 
@@ -126,10 +130,18 @@ void remove_block_from_lists(void **block, heap_t *heap) {
                 current_maptable_node = current_maptable_node->next;
             }
         }
+#ifdef COUNT_HOPS
+        remove_block(heap, block, &current_maptable_node->fixed_list_head);
+#else
         remove_block(block, &current_maptable_node->fixed_list_head);
+#endif /* COUNT_HOPS */
     } else {
 #endif /* WITH_FIXED_LISTS */
+#ifdef COUNT_HOPS
+        remove_block(heap, block, &heap->free_list_head);
+#else
         remove_block(block, &heap->free_list_head);
+#endif /* COUNT_HOPS */
 #ifdef WITH_FIXED_LISTS
     }
 #endif /* WITH_FIXED_LISTS */