mm/mm_heap: use struct mm_heap_config_s to init the memory heap

To avoid add new parameters to the mm_initialize_heap() and
mm_initialize_pool()

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
This commit is contained in:
Bowen Wang
2025-05-24 11:47:36 +08:00
committed by GUIDINGLI
parent 32f504c8f5
commit e686a3ac42
8 changed files with 90 additions and 52 deletions
+12 -14
View File
@@ -998,12 +998,7 @@ bool mm_heapmember(FAR struct mm_heap_s *heap, FAR void *mem)
* heap region.
*
* Input Parameters:
* heap - If heap is NULL, will use heapstart initialize heap context,
* otherwise, will use heap alloc a heap context, caller need
* free it after mm_uninitialize.
* name - The heap procfs name
* heapstart - Start of the initial heap region
* heapsize - Size of the initial heap region
* config - The heap config structure
*
* Returned Value:
* Return the address of a new heap instance.
@@ -1013,9 +1008,13 @@ bool mm_heapmember(FAR struct mm_heap_s *heap, FAR void *mem)
****************************************************************************/
FAR struct mm_heap_s *
mm_initialize_heap(FAR struct mm_heap_s *heap, FAR const char *name,
FAR void *heapstart, size_t heapsize)
mm_initialize_heap(FAR const struct mm_heap_config_s *config)
{
FAR struct mm_heap_s *heap = config->heap;
FAR const char *name = config->name;
FAR void *heapstart = config->start;
size_t heapsize = config->size;
minfo("Heap: name=%s start=%p size=%zu\n", name, heapstart, heapsize);
if (heap == NULL)
{
@@ -1070,11 +1069,10 @@ mm_initialize_heap(FAR struct mm_heap_s *heap, FAR const char *name,
#ifdef CONFIG_MM_HEAP_MEMPOOL
FAR struct mm_heap_s *
mm_initialize_pool(FAR struct mm_heap_s *heap,
FAR const char *name,
FAR void *heap_start, size_t heap_size,
mm_initialize_pool(FAR const struct mm_heap_config_s *config,
FAR const struct mempool_init_s *init)
{
FAR struct mm_heap_s *heap;
#if CONFIG_MM_HEAP_MEMPOOL_THRESHOLD > 0
size_t poolsize[MEMPOOL_NPOOLS];
struct mempool_init_s def;
@@ -1105,15 +1103,15 @@ mm_initialize_pool(FAR struct mm_heap_s *heap,
}
#endif
heap = mm_initialize_heap(heap, name, heap_start, heap_size);
heap = mm_initialize_heap(config);
/* Initialize the multiple mempool in heap */
if (init != NULL && init->poolsize != NULL && init->npools != 0)
{
heap->mm_threshold = init->threshold;
heap->mm_mpool = mempool_multiple_init(name, init->poolsize,
init->npools,
heap->mm_mpool = mempool_multiple_init(config->name,
init->poolsize, init->npools,
(mempool_multiple_alloc_t)mempool_memalign,
(mempool_multiple_alloc_size_t)mm_malloc_size,
(mempool_multiple_free_t)mm_free, heap,