From 706d9f6db2bdaa6db80794eec96bfae14e6f8773 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 8 May 2023 14:56:00 -0700 Subject: [PATCH] libc/common: Use static initializer for z_malloc_heap_mutex Instead of explicitly initializing the mutex at runtime, use SYS_MUTEX_DEFINE to initialize it at build time instead. Signed-off-by: Keith Packard --- lib/libc/common/source/stdlib/malloc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/libc/common/source/stdlib/malloc.c b/lib/libc/common/source/stdlib/malloc.c index 21ac95c8521..e87a633cfe0 100644 --- a/lib/libc/common/source/stdlib/malloc.c +++ b/lib/libc/common/source/stdlib/malloc.c @@ -31,8 +31,10 @@ LOG_MODULE_DECLARE(os, CONFIG_KERNEL_LOG_LEVEL); # if Z_MALLOC_PARTITION_EXISTS K_APPMEM_PARTITION_DEFINE(z_malloc_partition); # define POOL_SECTION Z_GENERIC_SECTION(K_APP_DMEM_SECTION(z_malloc_partition)) +# define MALLOC_SECTION Z_GENERIC_SECTION(K_APP_DMEM_SECTION(z_malloc_partition)) # else # define POOL_SECTION __noinit +# define MALLOC_SECTION # endif /* CONFIG_USERSPACE */ # if defined(CONFIG_MMU) && CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE < 0 @@ -110,7 +112,7 @@ extern char _heap_sentry[]; # endif /* else ALLOCATE_HEAP_AT_STARTUP */ POOL_SECTION static struct sys_heap z_malloc_heap; -POOL_SECTION struct sys_mutex z_malloc_heap_mutex; +MALLOC_SECTION SYS_MUTEX_DEFINE(z_malloc_heap_mutex); void *malloc(size_t size) { @@ -195,7 +197,6 @@ static int malloc_prepare(void) #endif sys_heap_init(&z_malloc_heap, heap_base, heap_size); - sys_mutex_init(&z_malloc_heap_mutex); return 0; }