From 6ccfe722bda09ab469d4a9cb2d78666f16955607 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Thu, 9 Aug 2012 10:17:42 +0200 Subject: score: Change _Heap_Extend() API The _Heap_Extend() has now the same signature as _Heap_Initialize(). The 4th parameter is ignored (page size in _Heap_Initialize()). Add Heap_Area and Heap_Initialization_or_extend_handler. Add and test _Heap_No_extend(). This helps to do a table based heap initialization and extension. Create a table of Heap_Area elements and iterate through it. Set the handler to _Heap_Initialize() in the first iteration and then to _Heap_Extend(). --- cpukit/score/Makefile.am | 2 +- cpukit/score/include/rtems/score/heap.h | 59 +++++++++++++++++++++++++++++---- cpukit/score/src/heapextend.c | 15 ++++----- cpukit/score/src/heapnoextend.c | 37 +++++++++++++++++++++ cpukit/score/src/pheapextend.c | 7 ++-- 5 files changed, 100 insertions(+), 20 deletions(-) create mode 100644 cpukit/score/src/heapnoextend.c (limited to 'cpukit/score') diff --git a/cpukit/score/Makefile.am b/cpukit/score/Makefile.am index 6f9f94f3bf..d259acb483 100644 --- a/cpukit/score/Makefile.am +++ b/cpukit/score/Makefile.am @@ -178,7 +178,7 @@ endif libscore_a_SOURCES += src/heap.c src/heapallocate.c src/heapextend.c \ src/heapfree.c src/heapsizeofuserarea.c src/heapwalk.c src/heapgetinfo.c \ src/heapgetfreeinfo.c src/heapresizeblock.c src/heapiterate.c \ - src/heapgreedy.c + src/heapgreedy.c src/heapnoextend.c ## OBJECT_C_FILES libscore_a_SOURCES += src/objectallocate.c src/objectclose.c \ diff --git a/cpukit/score/include/rtems/score/heap.h b/cpukit/score/include/rtems/score/heap.h index 8e6220cc2e..964386a36f 100644 --- a/cpukit/score/include/rtems/score/heap.h +++ b/cpukit/score/include/rtems/score/heap.h @@ -387,6 +387,33 @@ typedef enum { HEAP_RESIZE_FATAL_ERROR } Heap_Resize_status; +/** + * @brief Heap area structure for table based heap initialization and + * extension. + * + * @see Heap_Initialization_or_extend_handler. + */ +typedef struct { + void *begin; + uintptr_t size; +} Heap_Area; + +/** + * @brief Heap initialization and extend handler type. + * + * This helps to do a table based heap initialization and extension. Create a + * table of Heap_Area elements and iterate through it. Set the handler to + * _Heap_Initialize() in the first iteration and then to _Heap_Extend(). + * + * @see Heap_Area, _Heap_Initialize(), _Heap_Extend(), or _Heap_No_extend(). + */ +typedef uintptr_t (*Heap_Initialization_or_extend_handler)( + Heap_Control *heap, + void *area_begin, + uintptr_t area_size, + uintptr_t page_size_or_unused +); + /** * @brief Gets the first and last block for the heap area with begin * @a heap_area_begin and size @a heap_area_size. @@ -419,6 +446,8 @@ bool _Heap_Get_first_and_last_block( * @c CPU_ALIGNMENT, it is aligned up to the nearest @c CPU_ALIGNMENT boundary. * * Returns the maximum memory available, or zero in case of failure. + * + * @see Heap_Initialization_or_extend_handler. */ uintptr_t _Heap_Initialize( Heap_Control *heap, @@ -431,22 +460,40 @@ uintptr_t _Heap_Initialize( * @brief Extends the memory available for the heap @a heap using the memory * area starting at @a area_begin of size @a area_size bytes. * - * The extended space available for allocation will be returned in - * @a amount_extended. This pointer may be @c NULL. - * * There are no alignment requirements. The memory area must be big enough to * contain some maintainance blocks. It must not overlap parts of the current * heap areas. Disconnected subordinate heap areas will lead to used blocks * which cover the gaps. Extending with an inappropriate memory area will * corrupt the heap. * - * Returns @c true in case of success, and @c false otherwise. + * The unused fourth parameter is provided to have the same signature as + * _Heap_Initialize(). + * + * Returns the extended space available for allocation, or zero in case of failure. + * + * @see Heap_Initialization_or_extend_handler. */ -bool _Heap_Extend( +uintptr_t _Heap_Extend( Heap_Control *heap, void *area_begin, uintptr_t area_size, - uintptr_t *amount_extended + uintptr_t unused +); + +/** + * @brief This function returns always zero. + * + * This function only returns zero and does nothing else. + * + * Returns always zero. + * + * @see Heap_Initialization_or_extend_handler. + */ +uintptr_t _Heap_No_extend( + Heap_Control *unused_0, + void *unused_1, + uintptr_t unused_2, + uintptr_t unused_3 ); /** diff --git a/cpukit/score/src/heapextend.c b/cpukit/score/src/heapextend.c index 9d2d587312..f93d71f906 100644 --- a/cpukit/score/src/heapextend.c +++ b/cpukit/score/src/heapextend.c @@ -108,11 +108,11 @@ static void _Heap_Link_above( last_block->size_and_flag |= HEAP_PREV_BLOCK_USED; } -bool _Heap_Extend( +uintptr_t _Heap_Extend( Heap_Control *heap, void *extend_area_begin_ptr, uintptr_t extend_area_size, - uintptr_t *extended_size_ptr + uintptr_t unused __attribute__((unused)) ) { Heap_Statistics *const stats = &heap->stats; @@ -134,7 +134,7 @@ bool _Heap_Extend( bool extend_area_ok = false; if ( extend_area_end < extend_area_begin ) { - return false; + return 0; } extend_area_ok = _Heap_Get_first_and_last_block( @@ -147,7 +147,7 @@ bool _Heap_Extend( ); if (!extend_area_ok ) { /* For simplicity we reject extend areas that are too small */ - return false; + return 0; } do { @@ -160,7 +160,7 @@ bool _Heap_Extend( if ( sub_area_end > extend_area_begin && extend_area_end > sub_area_begin ) { - return false; + return 0; } if ( extend_area_end == sub_area_begin ) { @@ -234,8 +234,5 @@ bool _Heap_Extend( /* Statistics */ stats->size += extended_size; - if ( extended_size_ptr != NULL ) - *extended_size_ptr = extended_size; - - return true; + return extended_size; } diff --git a/cpukit/score/src/heapnoextend.c b/cpukit/score/src/heapnoextend.c new file mode 100644 index 0000000000..1652f59e17 --- /dev/null +++ b/cpukit/score/src/heapnoextend.c @@ -0,0 +1,37 @@ +/** + * @file + * + * @ingroup ScoreHeap + * + * @brief Heap Handler implementation. + */ + +/* + * Copyright (c) 2012 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Obere Lagerstr. 30 + * 82178 Puchheim + * Germany + * + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + */ + +#if HAVE_CONFIG_H + #include "config.h" +#endif + +#include + +uintptr_t _Heap_No_extend( + Heap_Control *unused_0 __attribute__((unused)), + void *unused_1 __attribute__((unused)), + uintptr_t unused_2 __attribute__((unused)), + uintptr_t unused_3 __attribute__((unused)) +) +{ + return 0; +} diff --git a/cpukit/score/src/pheapextend.c b/cpukit/score/src/pheapextend.c index be23c706e3..5f1a4df8a6 100644 --- a/cpukit/score/src/pheapextend.c +++ b/cpukit/score/src/pheapextend.c @@ -28,12 +28,11 @@ bool _Protected_heap_Extend( uintptr_t size ) { - bool extend_ok; uintptr_t amount_extended; _RTEMS_Lock_allocator(); - extend_ok = _Heap_Extend(the_heap, starting_address, size, &amount_extended); + amount_extended = _Heap_Extend( the_heap, starting_address, size, 0 ); _RTEMS_Unlock_allocator(); - return extend_ok; -} + return amount_extended != 0; +} -- cgit v1.2.3