From a5afaee3d027a66148b0f184d401ed76e6c0f8ff Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Wed, 1 Nov 2023 21:13:00 +0000 Subject: heap_free_page returns true if page was successfully deleted --- lib/heap.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'lib/heap.c') diff --git a/lib/heap.c b/lib/heap.c index 6d44919..7dd7a12 100644 --- a/lib/heap.c +++ b/lib/heap.c @@ -31,17 +31,17 @@ void heap_create(heap_t *heap) heap->pages = 0; } -void heap_free_page(heap_t *heap, page_t *page) +bool heap_free_page(heap_t *heap, page_t *page) { if (!page || !heap) - return; + return false; if (page == heap->beg) { heap->beg = heap->beg->next; page_delete(page); --heap->pages; - return; + return true; } page_t *prev = NULL, *next = NULL, *cur = NULL; @@ -55,7 +55,7 @@ void heap_free_page(heap_t *heap, page_t *page) if (!cur) // Couldn't find the page - return; + return false; // Page was found prev->next = next; if (!next) @@ -63,6 +63,8 @@ void heap_free_page(heap_t *heap, page_t *page) heap->end = prev; page_delete(page); --heap->pages; + + return true; } page_t *heap_allocate(heap_t *heap, size_t requested) -- cgit v1.2.3-13-gbd6f