diff options
author | Juan Manuel Tomás <jtomas1815@gmail.com> | 2020-04-20 00:31:15 -0300 |
---|---|---|
committer | Juan Manuel Tomás <jtomas1815@gmail.com> | 2020-04-20 00:31:15 -0300 |
commit | 7e9998311d5d5c657ea2a15091382c23ffeecd3b (patch) | |
tree | 77457e88d5f3cbc174f1a8d0226ff73abe670d19 /page.c | |
parent | e10c32d01e8416923226f211dd855824a8123dcd (diff) | |
download | jet-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.
Diffstat (limited to 'page.c')
-rw-r--r-- | page.c | 14 |
1 files changed, 8 insertions, 6 deletions
@@ -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) { |