summaryrefslogtreecommitdiffstats
path: root/cpukit/libcsupport/src
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2020-04-08 17:14:41 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2021-11-30 08:33:12 +0100
commitd7205f0083f8fdd0408404ce99c6eab9b8d120c7 (patch)
tree235c9be429a0e1576775079756d81032298305e1 /cpukit/libcsupport/src
parentscore: Optimize Workspace Handler initialization (diff)
downloadrtems-d7205f0083f8fdd0408404ce99c6eab9b8d120c7.tar.bz2
libc: Optimize malloc() initialization
The BSPs provide memory for the separate C Program Heap initialization via _Memory_Get(). Most BSPs provide exactly one memory area. Only two BSPs provide more than one memory area (arm/altera-cyclone-v and bsps/powerpc/mpc55xxevb). Only if more than one memory area is provided, there is a need to use _Heap_Extend(). Provide two implementations to initialize the separate C Program Heap and let the BSP select one of the implementations based on the number of provided memory areas. This gets rid of a dependency on _Heap_Extend(). It also avoids dead code sections for most BSPs. Change licence to BSD-2-Clause according to file history. Update #3053.
Diffstat (limited to 'cpukit/libcsupport/src')
-rw-r--r--cpukit/libcsupport/src/malloc_initialize.c81
-rw-r--r--cpukit/libcsupport/src/mallocheap.c2
2 files changed, 1 insertions, 82 deletions
diff --git a/cpukit/libcsupport/src/malloc_initialize.c b/cpukit/libcsupport/src/malloc_initialize.c
deleted file mode 100644
index fb0999df01..0000000000
--- a/cpukit/libcsupport/src/malloc_initialize.c
+++ /dev/null
@@ -1,81 +0,0 @@
-/**
- * @file
- *
- * @brief RTEMS_Malloc_Initialize() implementation.
- */
-
-/*
- * COPYRIGHT (c) 1989-2012.
- * On-Line Applications Research Corporation (OAR).
- *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rtems.org/license/LICENSE.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <rtems/malloc.h>
-#include <rtems/score/wkspace.h>
-
-#include "malloc_p.h"
-
-#ifdef RTEMS_NEWLIB
-static Heap_Control _Malloc_Heap;
-
-Heap_Control *RTEMS_Malloc_Initialize(
- const Memory_Information *mem,
- Heap_Initialization_or_extend_handler extend
-)
-{
- Heap_Control *heap;
- Heap_Initialization_or_extend_handler init_or_extend;
- uintptr_t page_size;
- size_t i;
-
- heap = &_Malloc_Heap;
- RTEMS_Malloc_Heap = heap;
- init_or_extend = _Heap_Initialize;
- page_size = CPU_HEAP_ALIGNMENT;
-
- for (i = 0; i < _Memory_Get_count( mem ); ++i) {
- Memory_Area *area;
- uintptr_t space_available;
-
- area = _Memory_Get_area( mem, i );
- space_available = ( *init_or_extend )(
- heap,
- _Memory_Get_free_begin( area ),
- _Memory_Get_free_size( area ),
- page_size
- );
-
- if ( space_available > 0 ) {
- _Memory_Consume( area, _Memory_Get_free_size( area ) );
- init_or_extend = extend;
- }
- }
-
- if ( init_or_extend == _Heap_Initialize ) {
- _Internal_error( INTERNAL_ERROR_NO_MEMORY_FOR_HEAP );
- }
-
- return heap;
-}
-#else
-Heap_Control *RTEMS_Malloc_Initialize(
- const Memory_Information *mem,
- Heap_Initialization_or_extend_handler extend
-)
-{
- /* FIXME: Dummy function */
- return NULL;
-}
-#endif
-
-Heap_Control *_Workspace_Malloc_initialize_separate( void )
-{
- return RTEMS_Malloc_Initialize( _Memory_Get(), _Heap_Extend );
-}
diff --git a/cpukit/libcsupport/src/mallocheap.c b/cpukit/libcsupport/src/mallocheap.c
index 006362f209..ec14e73763 100644
--- a/cpukit/libcsupport/src/mallocheap.c
+++ b/cpukit/libcsupport/src/mallocheap.c
@@ -44,7 +44,7 @@
Heap_Control *RTEMS_Malloc_Heap;
-static void _Malloc_Initialize( void )
+void _Malloc_Initialize( void )
{
RTEMS_Malloc_Heap = ( *_Workspace_Malloc_initializer )();
}