diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2012-02-10 10:36:26 +0100 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2012-02-10 10:42:58 +0100 |
commit | 28a08877ea961b0440b121b4617919136d6f342d (patch) | |
tree | c20ca716fad23ca298e98cf03bd8262150c8108e /cpukit/libcsupport | |
parent | Moved empty test in front of busy tests (diff) | |
download | rtems-28a08877ea961b0440b121b4617919136d6f342d.tar.bz2 |
Added support functions for greedy heap allocation
Various tests must check program paths that result due to failed memory
allocations from the heap. To avoid tinkering with internal heap
structures throughout the test code these functions should be used.
Diffstat (limited to 'cpukit/libcsupport')
-rw-r--r-- | cpukit/libcsupport/Makefile.am | 3 | ||||
-rw-r--r-- | cpukit/libcsupport/include/rtems/malloc.h | 18 | ||||
-rw-r--r-- | cpukit/libcsupport/src/rtems_heap_greedy.c | 37 |
3 files changed, 57 insertions, 1 deletions
diff --git a/cpukit/libcsupport/Makefile.am b/cpukit/libcsupport/Makefile.am index ec06f901a1..15e55a1e51 100644 --- a/cpukit/libcsupport/Makefile.am +++ b/cpukit/libcsupport/Makefile.am @@ -107,7 +107,8 @@ MALLOC_C_FILES = src/malloc_initialize.c src/calloc.c src/malloc.c \ src/malloc_statistics_helpers.c src/posix_memalign.c \ src/rtems_memalign.c src/malloc_deferred.c src/malloc_sbrk_helpers.c \ src/malloc_dirtier.c src/malloc_p.h src/rtems_malloc.c \ - src/rtems_heap_extend.c + src/rtems_heap_extend.c \ + src/rtems_heap_greedy.c PASSWORD_GROUP_C_FILES = src/getpwent.c diff --git a/cpukit/libcsupport/include/rtems/malloc.h b/cpukit/libcsupport/include/rtems/malloc.h index e1dfb08445..a8eb434d3b 100644 --- a/cpukit/libcsupport/include/rtems/malloc.h +++ b/cpukit/libcsupport/include/rtems/malloc.h @@ -184,6 +184,24 @@ rtems_status_code rtems_heap_extend( uintptr_t area_size ); +/** + * @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. + * + * @see rtems_heap_greedy_free(). + */ +void *rtems_heap_greedy_allocate( size_t remaining_free_space ); + +/** + * @brief Frees space of a greedy allocation. + * + * The @a opaque argument must be the return value of + * rtems_heap_greedy_allocate(). + */ +void rtems_heap_greedy_free( void *opaque ); + #ifdef __cplusplus } #endif diff --git a/cpukit/libcsupport/src/rtems_heap_greedy.c b/cpukit/libcsupport/src/rtems_heap_greedy.c new file mode 100644 index 0000000000..d363fe4d3b --- /dev/null +++ b/cpukit/libcsupport/src/rtems_heap_greedy.c @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2012 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Obere Lagerstr. 30 + * 82178 Puchheim + * Germany + * <rtems@embedded-brains.de> + * + * 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 "malloc_p.h" + +void *rtems_heap_greedy_allocate( size_t remaining_free_space ) +{ + void *opaque; + + _RTEMS_Lock_allocator(); + opaque = _Heap_Greedy_allocate( RTEMS_Malloc_Heap, remaining_free_space ); + _RTEMS_Unlock_allocator(); + + return opaque; +} + +void rtems_heap_greedy_free( void *opaque ) +{ + _RTEMS_Lock_allocator(); + _Heap_Greedy_free( RTEMS_Malloc_Heap, opaque ); + _RTEMS_Unlock_allocator(); +} |