diff options
author | Joel Sherrill <joel.sherrill@OARcorp.com> | 2009-08-26 12:00:24 +0000 |
---|---|---|
committer | Joel Sherrill <joel.sherrill@OARcorp.com> | 2009-08-26 12:00:24 +0000 |
commit | 371cea31d3cffb1e1d2ae2e865d1e9a462a3fbd6 (patch) | |
tree | c407c96dda4ebe8580df10d35a12bc20dd8bc221 /cpukit/score/src/heapallocate.c | |
parent | Add mpfr_provided for openSUSE 11.0 + 11.1 (diff) | |
download | rtems-371cea31d3cffb1e1d2ae2e865d1e9a462a3fbd6.tar.bz2 |
2009-08-24 Sebastian Huber <Sebastian.Huber@embedded-brains.de>
* libmisc/stackchk/check.c, rtems/src/regionreturnsegment.c,
rtems/src/regiongetsegmentsize.c, src/heapalignupuptr.c,
src/heapallocatealigned.c, src/heapallocate.c, src/heap.c,
src/heapextend.c, src/heapfree.c, src/heapgetfreeinfo.c,
src/heapgetinfo.c, src/heapresizeblock.c, src/heapsizeofuserarea.c,
src/heapwalk.c, src/pheapgetblocksize.c, inline/rtems/score/heap.inl,
include/rtems/score/heap.h: Overall cleanup. Changed all types for
addresses, sizes, offsets and alignments to uintptr_t. Reformatted.
Added variables for clarity. Renamed various objects. Enabled
_HAssert() for all instances. More changes follow.
Diffstat (limited to 'cpukit/score/src/heapallocate.c')
-rw-r--r-- | cpukit/score/src/heapallocate.c | 79 |
1 files changed, 32 insertions, 47 deletions
diff --git a/cpukit/score/src/heapallocate.c b/cpukit/score/src/heapallocate.c index 86164d209c..7c9e78f31e 100644 --- a/cpukit/score/src/heapallocate.c +++ b/cpukit/score/src/heapallocate.c @@ -19,63 +19,48 @@ #include <rtems/score/sysstate.h> #include <rtems/score/heap.h> -/*PAGE - * - * _Heap_Allocate - * - * This kernel routine allocates the requested size of memory - * from the specified heap. - * - * Input parameters: - * the_heap - pointer to heap header. - * size - size in bytes of the memory block to allocate. - * - * Output parameters: - * returns - starting address of memory block allocated - */ - -void *_Heap_Allocate( - Heap_Control *the_heap, - intptr_t size -) +void *_Heap_Allocate( Heap_Control *heap, uintptr_t size ) { - uint32_t the_size; - uint32_t search_count; - Heap_Block *the_block; - void *ptr = NULL; - Heap_Statistics *const stats = &the_heap->stats; - Heap_Block *const tail = _Heap_Tail(the_heap); + Heap_Statistics *const stats = &heap->stats; + Heap_Block * const tail = _Heap_Free_list_tail( heap ); + Heap_Block *block = _Heap_First_free_block( heap ); + uint32_t search_count = 0; + void *alloc_area_begin_ptr = NULL; - the_size = - _Heap_Calc_block_size(size, the_heap->page_size, the_heap->min_block_size); - if(the_size == 0) + size = _Heap_Calc_block_size( size, heap->page_size, heap->min_block_size ); + if( size == 0 ) { return NULL; + } - /* Find large enough free block. */ - for(the_block = _Heap_First(the_heap), search_count = 0; - the_block != tail; - the_block = the_block->next, ++search_count) - { - /* As we always coalesce free blocks, prev block must have been used. */ - _HAssert(_Heap_Is_prev_used(the_block)); + /* + * Find large enough free block. + * + * Do not bother to mask out the HEAP_PREV_BLOCK_USED bit as it will not + * change the result of the size comparison. + */ + while (block != tail && block->size_and_flag < size) { + _HAssert( _Heap_Is_prev_used( block )); - /* Don't bother to mask out the HEAP_PREV_USED bit as it won't change the - result of the comparison. */ - if(the_block->size >= the_size) { - (void)_Heap_Block_allocate(the_heap, the_block, the_size ); + block = block->next; + ++search_count; + } - ptr = _Heap_User_area(the_block); + if (block != tail) { + _Heap_Block_allocate( heap, block, size ); - stats->allocs += 1; - stats->searches += search_count + 1; + alloc_area_begin_ptr = (void *) _Heap_Alloc_area_of_block( block ); - _HAssert(_Heap_Is_aligned_ptr(ptr, the_heap->page_size)); - break; - } + _HAssert( _Heap_Is_aligned( (uintptr_t) alloc_area_begin_ptr, heap->page_size )); + + /* Statistics */ + ++stats->allocs; + stats->searches += search_count; } - if(stats->max_search < search_count) + /* Statistics */ + if (stats->max_search < search_count) { stats->max_search = search_count; + } - return ptr; + return alloc_area_begin_ptr; } |