]> git.mdlowis.com Git - archive/atc.git/commitdiff
Implemented find and mark routine for large blocks
authorMichael D. Lowis <mike@mdlowis.com>
Sat, 4 Apr 2015 17:52:34 +0000 (13:52 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Sat, 4 Apr 2015 17:52:34 +0000 (13:52 -0400)
source/runtime/heap.c
tests/test_heap.c

index 3b8488507b953b7d0c57eb89d50e4b9fb1785817..58fac98073b2be931e0c967c5ab714993aa35d86 100644 (file)
@@ -77,6 +77,7 @@ void heap_start_collection(heap_t* heap)
 void heap_finish_collection(heap_t* heap)
 {
     destroy_large_blocks(heap->greylist);
+    heap->greylist = NULL;
 }
 
 static void* subheap_find_and_mark(heap_t* heap, uintptr_t addr) {
@@ -100,8 +101,16 @@ static void* block_find_and_mark(heap_t* heap, uintptr_t addr) {
     while (curr != NULL) {
         uintptr_t start = (uintptr_t)&(curr->data[0]);
         uintptr_t end   = start + curr->size;
-        if ((start <= addr) && (addr <= end)) {
-
+        if ((start <= addr) && (addr < end)) {
+            /* Remove it from the grey list */
+            if (prev == NULL)
+                heap->greylist = curr->next;
+            else
+                prev->next = curr->next;
+            /* Add it to the in-use list and break */
+            curr->next = heap->blocks;
+            heap->blocks = curr->next;
+            break;
         }
         prev = curr;
         curr = curr->next;
index 73ce97caf7c4b040f3f9e15ad06484dd2a2d775e..13acbdcd9cc49796febda2e323dc9814d680aa41 100644 (file)
@@ -11,7 +11,6 @@ TEST_SUITE(Heap) {
         CHECK(NULL != heap_allocate(heap, 64));
         CHECK(NULL != heap_allocate(heap, 65));
         heap_destroy(heap);
-        gc_collect();
     }
 
     /* Verify: heap_alloc