aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2023-11-01 21:13:00 +0000
committerAryadev Chavali <aryadev@aryadevchavali.com>2023-11-01 21:13:00 +0000
commita5afaee3d027a66148b0f184d401ed76e6c0f8ff (patch)
treec282759bc07a4113ec260619ddf151c51656b0ad
parent206dce7bab107651aa56dda8559b44958dc34a66 (diff)
downloadovm-a5afaee3d027a66148b0f184d401ed76e6c0f8ff.tar.gz
ovm-a5afaee3d027a66148b0f184d401ed76e6c0f8ff.tar.bz2
ovm-a5afaee3d027a66148b0f184d401ed76e6c0f8ff.zip
heap_free_page returns true if page was successfully deleted
-rw-r--r--lib/heap.c10
-rw-r--r--lib/heap.h3
2 files changed, 8 insertions, 5 deletions
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)
diff --git a/lib/heap.h b/lib/heap.h
index d289ffa..486f28c 100644
--- a/lib/heap.h
+++ b/lib/heap.h
@@ -15,6 +15,7 @@
#include "./base.h"
+#include <stdbool.h>
#include <stdlib.h>
typedef struct Page
@@ -34,7 +35,7 @@ typedef struct
} heap_t;
void heap_create(heap_t *);
-void heap_free_page(heap_t *, page_t *);
+bool heap_free_page(heap_t *, page_t *);
page_t *heap_allocate(heap_t *, size_t);
void heap_stop(heap_t *);