From f811637100167d73b803107e4172c996bf542534 Mon Sep 17 00:00:00 2001 From: chenrun1 Date: Wed, 13 Nov 2024 13:39:13 +0800 Subject: [PATCH] lib_pathbuffer: change nxmutex -> spinlock Summary: _assert | ->dump_fatal_info | ->dump_tasks | ->dump_filelist | ->files_dumplist | ->lib_get_pathbuffer | ->nxmutex_lock <-- hold mutex on assert will trigger an nested exception Signed-off-by: chenrun1 --- libs/libc/misc/lib_pathbuffer.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/libs/libc/misc/lib_pathbuffer.c b/libs/libc/misc/lib_pathbuffer.c index 6c022c3c738ba..3928130dc8b11 100644 --- a/libs/libc/misc/lib_pathbuffer.c +++ b/libs/libc/misc/lib_pathbuffer.c @@ -25,7 +25,7 @@ ****************************************************************************/ #include -#include +#include #include #include @@ -41,7 +41,7 @@ struct pathbuffer_s { - mutex_t lock; /* Lock for the buffer */ + spinlock_t lock; /* Lock for the buffer */ unsigned long free_bitmap; /* Bitmap of free buffer */ char buffer[CONFIG_LIBC_MAX_PATHBUFFER][PATH_MAX]; }; @@ -52,7 +52,7 @@ struct pathbuffer_s static struct pathbuffer_s g_pathbuffer = { - NXMUTEX_INITIALIZER, + SP_UNLOCKED, (1u << CONFIG_LIBC_MAX_PATHBUFFER) - 1, }; @@ -82,20 +82,21 @@ static struct pathbuffer_s g_pathbuffer = FAR char *lib_get_pathbuffer(void) { + irqstate_t flags; int index; /* Try to find a free buffer */ - nxmutex_lock(&g_pathbuffer.lock); + flags = spin_lock_irqsave(&g_pathbuffer.lock); index = ffsl(g_pathbuffer.free_bitmap) - 1; if (index >= 0 && index < CONFIG_LIBC_MAX_PATHBUFFER) { g_pathbuffer.free_bitmap &= ~(1u << index); - nxmutex_unlock(&g_pathbuffer.lock); + spin_unlock_irqrestore(&g_pathbuffer.lock, flags); return g_pathbuffer.buffer[index]; } - nxmutex_unlock(&g_pathbuffer.lock); + spin_unlock_irqrestore(&g_pathbuffer.lock, flags); /* If no free buffer is found, allocate a new one if * CONFIG_LIBC_PATHBUFFER_MALLOC is enabled @@ -124,22 +125,20 @@ FAR char *lib_get_pathbuffer(void) void lib_put_pathbuffer(FAR char *buffer) { + irqstate_t flags; int index; - nxmutex_lock(&g_pathbuffer.lock); index = (buffer - &g_pathbuffer.buffer[0][0]) / PATH_MAX; - if (index >= 0 && index < CONFIG_LIBC_MAX_PATHBUFFER) { /* Mark the corresponding bit as free */ + flags = spin_lock_irqsave(&g_pathbuffer.lock); g_pathbuffer.free_bitmap |= 1u << index; - nxmutex_unlock(&g_pathbuffer.lock); + spin_unlock_irqrestore(&g_pathbuffer.lock, flags); return; } - nxmutex_unlock(&g_pathbuffer.lock); - /* Free the buffer if it was dynamically allocated */ #ifdef CONFIG_LIBC_PATHBUFFER_MALLOC