summaryrefslogtreecommitdiffstats
path: root/cpukit/score/src/heapresizeblock.c
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2009-08-26 12:00:24 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2009-08-26 12:00:24 +0000
commit371cea31d3cffb1e1d2ae2e865d1e9a462a3fbd6 (patch)
treec407c96dda4ebe8580df10d35a12bc20dd8bc221 /cpukit/score/src/heapresizeblock.c
parentAdd mpfr_provided for openSUSE 11.0 + 11.1 (diff)
downloadrtems-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/heapresizeblock.c')
-rw-r--r--cpukit/score/src/heapresizeblock.c116
1 files changed, 46 insertions, 70 deletions
diff --git a/cpukit/score/src/heapresizeblock.c b/cpukit/score/src/heapresizeblock.c
index c744d4ff88..8916bbe12c 100644
--- a/cpukit/score/src/heapresizeblock.c
+++ b/cpukit/score/src/heapresizeblock.c
@@ -19,103 +19,79 @@
#include <rtems/score/sysstate.h>
#include <rtems/score/heap.h>
-/*
- * _Heap_Resize_block
- *
- * DESCRIPTION:
- *
- * This routine tries to resize in place the block that is pointed to by the
- * 'starting_address' to the new 'size'.
- *
- * Input parameters:
- * the_heap - pointer to heap header
- * starting_address - starting address of the memory block
- * size - new size
- *
- * Output parameters:
- * 'old_mem_size' - the size of the user memory area of the block before
- * resizing.
- * 'avail_mem_size' - the size of the user memory area of the free block
- * that has been enlarged or created due to resizing,
- * 0 if none.
- * Returns
- * HEAP_RESIZE_SUCCESSFUL - if success
- * HEAP_RESIZE_UNSATISFIED - if the block can't be resized in place
- * HEAP_RESIZE_FATAL_ERROR - if failure
- */
-
Heap_Resize_status _Heap_Resize_block(
- Heap_Control *the_heap,
- void *starting_address,
- intptr_t size,
- intptr_t *old_mem_size,
- intptr_t *avail_mem_size
+ Heap_Control *heap,
+ void *alloc_area_begin_ptr,
+ uintptr_t size,
+ uintptr_t *old_mem_size,
+ uintptr_t *avail_mem_size
)
{
- Heap_Block *the_block;
+ uintptr_t alloc_area_begin = (uintptr_t) alloc_area_begin_ptr;
+ Heap_Block *block;
Heap_Block *next_block;
- uint32_t next_block_size;
+ uintptr_t next_block_size;
bool next_is_used;
Heap_Block *next_next_block;
- uint32_t old_block_size;
- uint32_t old_user_size;
- uint32_t prev_used_flag;
- Heap_Statistics *const stats = &the_heap->stats;
- uint32_t const min_block_size = the_heap->min_block_size;
- uint32_t const page_size = the_heap->page_size;
+ uintptr_t old_block_size;
+ uintptr_t old_user_size;
+ uintptr_t prev_used_flag;
+ Heap_Statistics *const stats = &heap->stats;
+ uintptr_t const min_block_size = heap->min_block_size;
+ uintptr_t const page_size = heap->page_size;
*old_mem_size = 0;
*avail_mem_size = 0;
- _Heap_Start_of_block(the_heap, starting_address, &the_block);
- _HAssert(_Heap_Is_block_in(the_heap, the_block));
- if (!_Heap_Is_block_in(the_heap, the_block))
+ block = _Heap_Block_of_alloc_area(alloc_area_begin, heap->page_size);
+ _HAssert(_Heap_Is_block_in_heap(heap, block));
+ if (!_Heap_Is_block_in_heap(heap, block))
return HEAP_RESIZE_FATAL_ERROR;
- prev_used_flag = the_block->size & HEAP_PREV_USED;
- old_block_size = _Heap_Block_size(the_block);
- next_block = _Heap_Block_at(the_block, old_block_size);
+ prev_used_flag = block->size_and_flag & HEAP_PREV_BLOCK_USED;
+ old_block_size = _Heap_Block_size(block);
+ next_block = _Heap_Block_at(block, old_block_size);
- _HAssert(_Heap_Is_block_in(the_heap, next_block));
+ _HAssert(_Heap_Is_block_in_heap(heap, next_block));
_HAssert(_Heap_Is_prev_used(next_block));
- if ( !_Heap_Is_block_in(the_heap, next_block) ||
+ if ( !_Heap_Is_block_in_heap(heap, next_block) ||
!_Heap_Is_prev_used(next_block))
return HEAP_RESIZE_FATAL_ERROR;
next_block_size = _Heap_Block_size(next_block);
next_next_block = _Heap_Block_at(next_block, next_block_size);
- next_is_used = (next_block == the_heap->final) ||
+ next_is_used = (next_block == heap->final) ||
_Heap_Is_prev_used(next_next_block);
- /* See _Heap_Size_of_user_area() source for explanations */
- old_user_size = _Addresses_Subtract(next_block, starting_address)
- + HEAP_BLOCK_HEADER_OFFSET;
+ /* See _Heap_Size_of_alloc_area() source for explanations */
+ old_user_size = (uintptr_t) next_block - alloc_area_begin
+ + HEAP_BLOCK_SIZE_OFFSET;
*old_mem_size = old_user_size;
if (size > old_user_size) {
/* Need to extend the block: allocate part of the next block and then
- merge 'the_block' and allocated block together. */
+ merge 'block' and allocated block together. */
if (next_is_used) /* Next block is in use, -- no way to extend */
return HEAP_RESIZE_UNSATISFIED;
else {
- uint32_t add_block_size = size - old_user_size;
- _Heap_Align_up(&add_block_size, page_size);
+ uintptr_t add_block_size =
+ _Heap_Align_up(size - old_user_size, page_size);
if (add_block_size < min_block_size)
add_block_size = min_block_size;
if (add_block_size > next_block_size)
return HEAP_RESIZE_UNSATISFIED; /* Next block is too small or none. */
add_block_size =
- _Heap_Block_allocate(the_heap, next_block, add_block_size);
+ _Heap_Block_allocate(heap, next_block, add_block_size);
/* Merge two subsequent blocks */
- the_block->size = (old_block_size + add_block_size) | prev_used_flag;
+ block->size_and_flag = (old_block_size + add_block_size) | prev_used_flag;
--stats->used_blocks;
}
} else {
/* Calculate how much memory we could free */
- uint32_t free_block_size = old_user_size - size;
- _Heap_Align_down(&free_block_size, page_size);
+ uintptr_t free_block_size =
+ _Heap_Align_down(old_user_size - size, page_size);
if (free_block_size > 0) {
@@ -123,10 +99,10 @@ Heap_Resize_status _Heap_Resize_block(
can hold 'size' user bytes and still remain not shorter than
'min_block_size'. */
- uint32_t new_block_size = old_block_size - free_block_size;
+ uintptr_t new_block_size = old_block_size - free_block_size;
if (new_block_size < min_block_size) {
- uint32_t delta = min_block_size - new_block_size;
+ uintptr_t delta = min_block_size - new_block_size;
_HAssert(free_block_size >= delta);
free_block_size -= delta;
if (free_block_size == 0) {
@@ -144,25 +120,25 @@ Heap_Resize_status _Heap_Resize_block(
if (!next_is_used) {
/* Extend the next block to the low addresses by 'free_block_size' */
Heap_Block *const new_next_block =
- _Heap_Block_at(the_block, new_block_size);
- uint32_t const new_next_block_size =
+ _Heap_Block_at(block, new_block_size);
+ uintptr_t const new_next_block_size =
next_block_size + free_block_size;
- _HAssert(_Heap_Is_block_in(the_heap, next_next_block));
- the_block->size = new_block_size | prev_used_flag;
- new_next_block->size = new_next_block_size | HEAP_PREV_USED;
+ _HAssert(_Heap_Is_block_in_heap(heap, next_next_block));
+ block->size_and_flag = new_block_size | prev_used_flag;
+ new_next_block->size_and_flag = new_next_block_size | HEAP_PREV_BLOCK_USED;
next_next_block->prev_size = new_next_block_size;
- _Heap_Block_replace(next_block, new_next_block);
- the_heap->stats.free_size += free_block_size;
+ _Heap_Block_replace_in_free_list(next_block, new_next_block);
+ heap->stats.free_size += free_block_size;
*avail_mem_size = new_next_block_size - HEAP_BLOCK_USED_OVERHEAD;
} else if (free_block_size >= min_block_size) {
/* Split the block into 2 used parts, then free the second one. */
- the_block->size = new_block_size | prev_used_flag;
- next_block = _Heap_Block_at(the_block, new_block_size);
- next_block->size = free_block_size | HEAP_PREV_USED;
+ block->size_and_flag = new_block_size | prev_used_flag;
+ next_block = _Heap_Block_at(block, new_block_size);
+ next_block->size_and_flag = free_block_size | HEAP_PREV_BLOCK_USED;
++stats->used_blocks; /* We have created used block */
--stats->frees; /* Don't count next call in stats */
- _Heap_Free(the_heap, _Heap_User_area(next_block));
+ _Heap_Free(heap, (void *) _Heap_Alloc_area_of_block(next_block));
*avail_mem_size = free_block_size - HEAP_BLOCK_USED_OVERHEAD;
}
}