mirror of
https://github.com/apache/nuttx.git
synced 2026-05-22 22:20:01 +08:00
sched: add spinlock to sched_note_preemption and nxsched_critmon_preemption
Add spinlock protection to sched_note_preemption and nxsched_critmon_preemption. Ensures thread-safe access to global state in preemption notification and critical monitoring, preventing race conditions in SMP and interrupt contexts. Signed-off-by: hujun5 <hujun5@xiaomi.com>
This commit is contained in:
@@ -171,7 +171,8 @@ FAR static struct note_driver_s *
|
||||
static struct note_taskname_s g_note_taskname;
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_SCHED_INSTRUMENTATION_FILTER)
|
||||
#if defined(CONFIG_SCHED_INSTRUMENTATION_FILTER) || \
|
||||
defined(CONFIG_SCHED_INSTRUMENTATION_PREEMPTION)
|
||||
static spinlock_t g_note_lock;
|
||||
#endif
|
||||
|
||||
@@ -1056,7 +1057,9 @@ void sched_note_preemption(FAR struct tcb_s *tcb, bool locked)
|
||||
struct note_preempt_s note;
|
||||
FAR struct note_driver_s **driver;
|
||||
bool formatted = false;
|
||||
irqstate_t flags;
|
||||
|
||||
flags = spin_lock_irqsave_notrace(&g_note_lock);
|
||||
for (driver = g_note_drivers; *driver; driver++)
|
||||
{
|
||||
if (!note_isenabled(*driver))
|
||||
@@ -1088,6 +1091,8 @@ void sched_note_preemption(FAR struct tcb_s *tcb, bool locked)
|
||||
|
||||
note_add(*driver, ¬e, sizeof(struct note_preempt_s));
|
||||
}
|
||||
|
||||
spin_unlock_irqrestore_notrace(&g_note_lock, flags);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user