From d2261702927ca0a4a8c9239fabfa288c401fc199 Mon Sep 17 00:00:00 2001 From: hujun5 Date: Wed, 20 Nov 2024 20:12:42 +0800 Subject: [PATCH] assert: in assert we use small spinlock replace enter_critical_section reason: Since assert may synchronously wait to stop another CPU, potentially leading to a deadlock, we replace enter_critical_section with a small spinlock to avoid such a situation. Signed-off-by: hujun5 --- sched/misc/assert.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sched/misc/assert.c b/sched/misc/assert.c index c3c6f37e533..f07bad20f06 100644 --- a/sched/misc/assert.c +++ b/sched/misc/assert.c @@ -113,6 +113,8 @@ static noreturn_function int pause_cpu_handler(FAR void *arg); static bool g_cpu_paused[CONFIG_SMP_NCPUS]; #endif +static spinlock_t g_assert_lock = SP_UNLOCKED; + static uintptr_t g_last_regs[CONFIG_SMP_NCPUS][XCPTCONTEXT_REGS] aligned_data(XCPTCONTEXT_ALIGN); @@ -841,7 +843,7 @@ void _assert(FAR const char *filename, int linenum, flags = 0; /* suppress GCC warning */ if (os_ready) { - flags = enter_critical_section(); + flags = spin_lock_irqsave(&g_assert_lock); } #if CONFIG_BOARD_RESET_ON_ASSERT < 2 @@ -914,6 +916,6 @@ void _assert(FAR const char *filename, int linenum, if (os_ready) { - leave_critical_section(flags); + spin_unlock_irqrestore(&g_assert_lock, flags); } }