Parcourir la source

Introduced a way to remove blocks from both fixed and the free lists of a heap.

Ioannis Koutras il y a 13 ans
Parent
commit
872b47f270
2 fichiers modifiés avec 37 ajouts et 0 suppressions
  1. 9 0
      private-include/linked_lists/linked_lists.h
  2. 28 0
      src/linked_lists/linked_lists.c

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

@@ -32,6 +32,7 @@
 #else
 #include <sys/types.h>
 #endif /* LEON3 */
+#include <dmmlib/heap.h>
 
 /** The type of the pointer to a list node */
 #ifndef LEON3
@@ -107,4 +108,12 @@ void push_block(void **block, void **starting_node);
  */
 void remove_block(void **block, void **starting_node);
 
+/**
+ * Removes a memory block from any of the linked lists of free memory blocks.
+ *
+ * \param **block A pointer to the block to be removed.
+ * \param *heap A pointer to the heap which manages the block.
+ */
+void remove_block_from_lists(void **block, heap_t *heap);
+
 #endif /* LINKED_LISTS_H */

+ 28 - 0
src/linked_lists/linked_lists.c

@@ -100,3 +100,31 @@ void remove_block(void **block, void **starting_node) {
 }
 #endif /* BLOCKS_IN_DLL */
 
+void remove_block_from_lists(void **block, heap_t *heap) {
+#ifdef WITH_FIXED_LISTS
+    int fixed_list_id, i;
+#endif /* WITH_FIXED_LISTS */
+    size_t size;
+
+    size = get_size(*block);
+
+#ifdef WITH_FIXED_LISTS
+    /* Check if it is a block of a fixed list */
+    fixed_list_id = map_size_to_list(heap, size);
+    if(fixed_list_id != -1) {
+        /* If it is, find the fixed list and remove the block */
+        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;
+            }
+        }
+        remove_block(block, &current_maptable_node->fixed_list_head);
+    } else {
+#endif /* WITH_FIXED_LISTS */
+        remove_block(block, &heap->free_list_head);
+#ifdef WITH_FIXED_LISTS
+    }
+#endif /* WITH_FIXED_LISTS */
+}
+