diff options
author | Miles Bader <miles@lsi.nec.co.jp> | 2002-07-24 06:48:48 +0000 |
---|---|---|
committer | Miles Bader <miles@lsi.nec.co.jp> | 2002-07-24 06:48:48 +0000 |
commit | cf61ef0c0925e1ef2a66c59e2fb5f8e3a9fa2466 (patch) | |
tree | 926ef49441bdeb5e8614f8249dda41917d78381c /libc/stdlib/malloc/heap.h | |
parent | a4214b24913dbe9050e540ddd97376f2f79ceb63 (diff) |
Factor out some common code sequences into inline functions.
Diffstat (limited to 'libc/stdlib/malloc/heap.h')
-rw-r--r-- | libc/stdlib/malloc/heap.h | 66 |
1 files changed, 60 insertions, 6 deletions
diff --git a/libc/stdlib/malloc/heap.h b/libc/stdlib/malloc/heap.h index 589bf42b0..5207afe8e 100644 --- a/libc/stdlib/malloc/heap.h +++ b/libc/stdlib/malloc/heap.h @@ -115,14 +115,68 @@ static void HEAP_DEBUG (struct heap *heap, const char *str) extern inline void __heap_unlink_free_area (struct heap *heap, struct heap_free_area *fa) { - if (fa->next) - fa->next->prev = fa->prev; - if (fa->prev) - fa->prev->next = fa->next; - else - heap->free_areas = fa->next; + if (fa->next) + fa->next->prev = fa->prev; + if (fa->prev) + fa->prev->next = fa->next; + else + heap->free_areas = fa->next; +} + +/* Link the free-area FA between the existing free-area's PREV and NEXT in + HEAP. PREV and NEXT may be 0; if PREV is 0, FA is installed as the + first free-area. */ +extern inline void +__heap_link_free_area (struct heap *heap, struct heap_free_area *fa, + struct heap_free_area *prev, + struct heap_free_area *next) +{ + fa->next = next; + fa->prev = prev; + + if (prev) + prev->next = fa; + else + heap->free_areas = fa; + if (next) + next->prev = fa; } +/* Update the mutual links between the free-areas PREV and FA in HEAP. + PREV may be 0, in which case FA is installed as the first free-area (but + FA may not be 0). */ +extern inline void +__heap_link_free_area_after (struct heap *heap, + struct heap_free_area *fa, + struct heap_free_area *prev) +{ + if (prev) + prev->next = fa; + else + heap->free_areas = fa; + fa->prev = prev; +} + +/* Add a new free-area MEM, of length SIZE, in between the existing + free-area's PREV and NEXT in HEAP, and return a pointer to its header. + PREV and NEXT may be 0; if PREV is 0, MEM is installed as the first + free-area. */ +extern inline struct heap_free_area * +__heap_add_free_area (struct heap *heap, void *mem, size_t size, + struct heap_free_area *prev, + struct heap_free_area *next) +{ + struct heap_free_area *fa = (struct heap_free_area *) + ((char *)mem + size - sizeof (struct heap_free_area)); + + fa->size = size; + + __heap_link_free_area (heap, fa, prev, next); + + return fa; +} + + /* Allocate SIZE bytes from the front of the free-area FA in HEAP, and return the amount actually allocated (which may be more than SIZE). */ extern inline size_t |