From: Michael D. Lowis Date: Sat, 4 Apr 2015 17:52:34 +0000 (-0400) Subject: Implemented find and mark routine for large blocks X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=f445132b9c6b22f859ba63c053938220106d9856;p=archive%2Fatc.git Implemented find and mark routine for large blocks --- diff --git a/source/runtime/heap.c b/source/runtime/heap.c index 3b84885..58fac98 100644 --- a/source/runtime/heap.c +++ b/source/runtime/heap.c @@ -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; diff --git a/tests/test_heap.c b/tests/test_heap.c index 73ce97c..13acbdc 100644 --- a/tests/test_heap.c +++ b/tests/test_heap.c @@ -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