summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan Manuel Tomás <jtomas1815@gmail.com>2020-04-20 00:31:15 -0300
committerJuan Manuel Tomás <jtomas1815@gmail.com>2020-04-20 00:31:15 -0300
commit7e9998311d5d5c657ea2a15091382c23ffeecd3b (patch)
tree77457e88d5f3cbc174f1a8d0226ff73abe670d19
parente10c32d01e8416923226f211dd855824a8123dcd (diff)
downloadjet-7e9998311d5d5c657ea2a15091382c23ffeecd3b.tar.gz
jet-7e9998311d5d5c657ea2a15091382c23ffeecd3b.zip
Move page pointer on free
When freeing a page, its pointer will move to the previous page if available. If not it will move to the next page.
-rw-r--r--page.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/page.c b/page.c
index a41f2d5..fd4ae6e 100644
--- a/page.c
+++ b/page.c
@@ -42,14 +42,16 @@ void split_page(struct page *first_half) {
first_half->next = second_half;
}
-void free_page(struct page *page) {
- if (page->next) {
- page->next->prev = page->prev;
+void free_page(struct page **page) {
+ if ((*page)->prev) {
+ (*page)->prev->next = (*page)->next;
}
- if (page->prev) {
- page->prev->next = page->next;
+ if ((*page)->next) {
+ (*page)->next->prev = (*page)->prev;
}
- free(page);
+ struct page *tmp = *page;
+ *page = (*page)->prev ?: (*page)->next;
+ free(tmp);
}
void move_gap(struct page *page, int target) {