From 4cf1649a655d5c0edf30b2a5a5718eb4065d34a6 Mon Sep 17 00:00:00 2001 From: hujun5 Date: Fri, 1 Nov 2024 19:23:23 +0800 Subject: [PATCH] spinlock: add sched_lock to spin_lock_irqsave_wo_note reason: We aim to replace big locks with smaller ones. So we will use spin_lock_irqsave extensively to replace enter_critical_section in the subsequent process. We imitate the implementation of Linux by adding sched_lock to spin_lock_irqsave in order to address scenarios where sem_post occurs within spin_lock_irqsave, which can lead to spinlock failures and deadlocks. Signed-off-by: hujun5 --- include/nuttx/spinlock.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/nuttx/spinlock.h b/include/nuttx/spinlock.h index 9d4d56fd6e9c7..668442e8b8e40 100644 --- a/include/nuttx/spinlock.h +++ b/include/nuttx/spinlock.h @@ -592,6 +592,7 @@ irqstate_t spin_lock_irqsave_wo_note(FAR volatile spinlock_t *lock) while (!spin_trylock_irqsave_wo_note(lock, ret)); } + sched_lock_wo_note(); return ret; } #else @@ -721,6 +722,7 @@ void spin_unlock_irqrestore_wo_note(FAR volatile spinlock_t *lock, } up_irq_restore(flags); + sched_unlock_wo_note(); } #else # define spin_unlock_irqrestore_wo_note(l, f) ((void)(l), up_irq_restore(f))