From 518c2aeba262cdad2c58bf581c7a49c2966d6569 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Wed, 9 Sep 2009 14:58:37 +0000 Subject: 2009-09-09 Sebastian Huber * score/include/rtems/score/heap.h, score/inline/rtems/score/heap.inl, score/src/heapallocate.c, score/src/heap.c, score/src/heapextend.c, score/src/heapresizeblock.c, score/src/heapwalk.c: Documenation. Simplified block resize. Improved heap walk. Changed heap layout to avoid a special case for _Heap_Is_used() and _Heap_Is_free(). * libmisc/stackchk/check.c: Update for heap API changes. --- cpukit/score/include/rtems/score/heap.h | 59 ++++++++++++++++++++++++--------- 1 file changed, 44 insertions(+), 15 deletions(-) (limited to 'cpukit/score/include/rtems/score/heap.h') diff --git a/cpukit/score/include/rtems/score/heap.h b/cpukit/score/include/rtems/score/heap.h index d07eac3baf..10a267526e 100644 --- a/cpukit/score/include/rtems/score/heap.h +++ b/cpukit/score/include/rtems/score/heap.h @@ -91,7 +91,7 @@ extern "C" { * The heap area after initialization contains two blocks and looks like: * * - * + * * * * @@ -108,14 +108,18 @@ extern "C" { * * * - * + * * * - * - * + * + * * - * + * *
LabelContent
heap->beginheap area begin address
heap->area_beginheap area begin address
first_block->prev_sizepage size (the value is arbitrary)
first_block->prev_Heap_Free_list_head(heap)
...
second_block->prev_sizesize of first blocklast_block->prev_sizesize of first block
second_block->sizepage size (the value is arbitrary)last_block->sizefirst block begin address - last block begin address
heap->endheap area end address
heap->area_endheap area end address
+ * The next block of the last block is the first block. Since the first + * block indicates that the previous block is used, this ensures that the + * last block appears as used for the _Heap_Is_used() and _Heap_Is_free() + * functions. * * @{ */ @@ -205,17 +209,23 @@ typedef struct { uint32_t instance; /** - * @brief The size of the memory for heap. + * @brief Size of the allocatable area in bytes. + * + * This value is an integral multiple of the page size. */ uintptr_t size; /** - * @brief Current free size. + * @brief Current free size in bytes. + * + * This value is an integral multiple of the page size. */ uintptr_t free_size; /** - * @brief Minimum free size ever. + * @brief Minimum free size ever in bytes. + * + * This value is an integral multiple of the page size. */ uintptr_t min_free_size; @@ -240,7 +250,7 @@ typedef struct { uint32_t max_search; /** - * @brief Total number of successful calls to alloc. + * @brief Total number of successful allocations. */ uint32_t allocs; @@ -354,7 +364,7 @@ Heap_Extend_status _Heap_Extend( ); /** - * @brief Allocates a memory area of size @a size bytes. + * @brief Allocates a memory area of size @a size bytes from the heap @a heap. * * If the alignment parameter @a alignment is not equal to zero, the allocated * memory area will begin at an address aligned by this value. @@ -378,11 +388,26 @@ void *_Heap_Allocate_aligned_with_boundary( uintptr_t boundary ); -#define _Heap_Allocate_aligned( heap, size, alignment ) \ - _Heap_Allocate_aligned_with_boundary( heap, size, alignment, 0 ) +/** + * @brief See _Heap_Allocate_aligned_with_boundary() with boundary equals zero. + */ +RTEMS_INLINE_ROUTINE void *_Heap_Allocate_aligned( + Heap_Control *heap, + uintptr_t size, + uintptr_t alignment +) +{ + return _Heap_Allocate_aligned_with_boundary( heap, size, alignment, 0 ); +} -#define _Heap_Allocate( heap, size ) \ - _Heap_Allocate_aligned_with_boundary( heap, size, 0, 0 ) +/** + * @brief See _Heap_Allocate_aligned_with_boundary() with alignment and + * boundary equals zero. + */ +RTEMS_INLINE_ROUTINE void *_Heap_Allocate( Heap_Control *heap, uintptr_t size ) +{ + return _Heap_Allocate_aligned_with_boundary( heap, size, 0, 0 ); +} /** * @brief Frees the allocated memory area starting at @a addr in the heap @@ -473,7 +498,11 @@ Heap_Resize_status _Heap_Resize_block( * @brief Allocates the memory area starting at @a alloc_begin of size * @a alloc_size bytes in the block @a block. * - * The block may be split up into multiple blocks. + * The block may be split up into multiple blocks. The previous and next block + * may be used or free. Free block parts which form a vaild new block will be + * inserted into the free list or merged with an adjacent free block. If the + * block is used, they will be inserted after the free list head. If the block + * is free, they will be inserted after the previous block in the free list. * * Inappropriate values for @a alloc_begin or @a alloc_size may corrupt the * heap. -- cgit v1.2.3