diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2012-07-17 10:19:16 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2012-07-17 10:19:16 +0200 |
commit | 317ee8d7ffd4bb6c785f7a7d8a84ccd7f873513f (patch) | |
tree | f51362b3092abb782995f9c9d59e0252a660d3ac /cpukit | |
parent | Fix broken _endtext symbol (diff) | |
download | rtems-317ee8d7ffd4bb6c785f7a7d8a84ccd7f873513f.tar.bz2 |
score: Change greedy allocation API
Diffstat (limited to 'cpukit')
-rw-r--r-- | cpukit/libcsupport/include/rtems/malloc.h | 10 | ||||
-rw-r--r-- | cpukit/libcsupport/src/rtems_heap_greedy.c | 7 | ||||
-rw-r--r-- | cpukit/rtems/include/rtems/rtems/support.h | 10 | ||||
-rw-r--r-- | cpukit/rtems/src/workspacegreedy.c | 7 | ||||
-rw-r--r-- | cpukit/score/include/rtems/score/heap.h | 8 | ||||
-rw-r--r-- | cpukit/score/src/heapgreedy.c | 33 |
6 files changed, 54 insertions, 21 deletions
diff --git a/cpukit/libcsupport/include/rtems/malloc.h b/cpukit/libcsupport/include/rtems/malloc.h index 7f56a842e5..d178e8a00d 100644 --- a/cpukit/libcsupport/include/rtems/malloc.h +++ b/cpukit/libcsupport/include/rtems/malloc.h @@ -186,12 +186,16 @@ rtems_status_code rtems_heap_extend( /** * @brief Greedy allocate that empties the heap. * - * Afterward the heap has at most @a remaining_free_space free space left in - * one free block. All other blocks are used. + * Afterward the heap has at most @a block_count allocateable blocks of sizes + * specified by @a block_sizes. The @a block_sizes must point to an array with + * @a block_count members. All other blocks are used. * * @see rtems_heap_greedy_free(). */ -void *rtems_heap_greedy_allocate( size_t remaining_free_space ); +void *rtems_heap_greedy_allocate( + const uintptr_t *block_sizes, + size_t block_count +); /** * @brief Frees space of a greedy allocation. diff --git a/cpukit/libcsupport/src/rtems_heap_greedy.c b/cpukit/libcsupport/src/rtems_heap_greedy.c index d363fe4d3b..7e5dc16e7e 100644 --- a/cpukit/libcsupport/src/rtems_heap_greedy.c +++ b/cpukit/libcsupport/src/rtems_heap_greedy.c @@ -18,12 +18,15 @@ #include "malloc_p.h" -void *rtems_heap_greedy_allocate( size_t remaining_free_space ) +void *rtems_heap_greedy_allocate( + const uintptr_t *block_sizes, + size_t block_count +) { void *opaque; _RTEMS_Lock_allocator(); - opaque = _Heap_Greedy_allocate( RTEMS_Malloc_Heap, remaining_free_space ); + opaque = _Heap_Greedy_allocate( RTEMS_Malloc_Heap, block_sizes, block_count ); _RTEMS_Unlock_allocator(); return opaque; diff --git a/cpukit/rtems/include/rtems/rtems/support.h b/cpukit/rtems/include/rtems/rtems/support.h index bdabc59e8b..b2c6471c31 100644 --- a/cpukit/rtems/include/rtems/rtems/support.h +++ b/cpukit/rtems/include/rtems/rtems/support.h @@ -102,12 +102,16 @@ bool rtems_workspace_free( /** * @brief Greedy allocate that empties the workspace. * - * Afterward the workspace has at most @a remaining_free_space free space left - * in one free block. All other blocks are used. + * Afterward the heap has at most @a block_count allocateable blocks of sizes + * specified by @a block_sizes. The @a block_sizes must point to an array with + * @a block_count members. All other blocks are used. * * @see rtems_workspace_greedy_free(). */ -void *rtems_workspace_greedy_allocate( size_t remaining_free_space ); +void *rtems_workspace_greedy_allocate( + const uintptr_t *block_sizes, + size_t block_count +); /** * @brief Frees space of a greedy allocation. diff --git a/cpukit/rtems/src/workspacegreedy.c b/cpukit/rtems/src/workspacegreedy.c index 6d8fd9b937..03781412b2 100644 --- a/cpukit/rtems/src/workspacegreedy.c +++ b/cpukit/rtems/src/workspacegreedy.c @@ -19,12 +19,15 @@ #include <rtems/rtems/support.h> #include <rtems/score/wkspace.h> -void *rtems_workspace_greedy_allocate( size_t remaining_free_space ) +void *rtems_workspace_greedy_allocate( + const uintptr_t *block_sizes, + size_t block_count +) { void *opaque; _Thread_Disable_dispatch(); - opaque = _Heap_Greedy_allocate( &_Workspace_Area, remaining_free_space ); + opaque = _Heap_Greedy_allocate( &_Workspace_Area, block_sizes, block_count ); _Thread_Enable_dispatch(); return opaque; diff --git a/cpukit/score/include/rtems/score/heap.h b/cpukit/score/include/rtems/score/heap.h index 9208d17ef4..8e6220cc2e 100644 --- a/cpukit/score/include/rtems/score/heap.h +++ b/cpukit/score/include/rtems/score/heap.h @@ -549,14 +549,16 @@ void _Heap_Iterate( /** * @brief Greedy allocate that empties the heap. * - * Afterward the heap has at most @a remaining_free_space free space left in - * one free block. All other blocks are used. + * Afterward the heap has at most @a block_count allocateable blocks of sizes + * specified by @a block_sizes. The @a block_sizes must point to an array with + * @a block_count members. All other blocks are used. * * @see _Heap_Greedy_free(). */ Heap_Block *_Heap_Greedy_allocate( Heap_Control *heap, - uintptr_t remaining_free_space + const uintptr_t *block_sizes, + size_t block_count ); /** diff --git a/cpukit/score/src/heapgreedy.c b/cpukit/score/src/heapgreedy.c index 4b38b7858a..4711bd5833 100644 --- a/cpukit/score/src/heapgreedy.c +++ b/cpukit/score/src/heapgreedy.c @@ -20,17 +20,31 @@ Heap_Block *_Heap_Greedy_allocate( Heap_Control *heap, - uintptr_t remaining_free_space + const uintptr_t *block_sizes, + size_t block_count ) { - void *free_space = remaining_free_space > 0 ? - _Heap_Allocate( heap, remaining_free_space ) - : NULL; Heap_Block *const free_list_tail = _Heap_Free_list_tail( heap ); - Heap_Block *current = _Heap_Free_list_first( heap ); + Heap_Block *allocated_blocks = NULL; Heap_Block *blocks = NULL; + Heap_Block *current; + size_t i; - while ( current != free_list_tail ) { + for (i = 0; i < block_count; ++i) { + void *next = _Heap_Allocate( heap, block_sizes [i] ); + + if ( next != NULL ) { + Heap_Block *next_block = _Heap_Block_of_alloc_area( + (uintptr_t) next, + heap->page_size + ); + + next_block->next = allocated_blocks; + allocated_blocks = next_block; + } + } + + while ( (current = _Heap_Free_list_first( heap )) != free_list_tail ) { _Heap_Block_allocate( heap, current, @@ -40,10 +54,13 @@ Heap_Block *_Heap_Greedy_allocate( current->next = blocks; blocks = current; - current = _Heap_Free_list_first( heap ); } - _Heap_Free( heap, free_space ); + while ( allocated_blocks != NULL ) { + current = allocated_blocks; + allocated_blocks = allocated_blocks->next; + _Heap_Free( heap, (void *) _Heap_Alloc_area_of_block( current ) ); + } return blocks; } |