From bc3d478749edbc6baf7157c6f2497a255d56176b Mon Sep 17 00:00:00 2001 From: hujun5 Date: Thu, 5 Jun 2025 21:11:42 +0800 Subject: [PATCH] sched/pthread: use spin_lock_irqsave_nopreempt for mutex head lock Replace spin_lock_irqsave with spin_lock_irqsave_nopreempt in pthread_mutex_inconsistent to prevent preemption during mutex list manipulation and avoid potential deadlocks or race conditions. Signed-off-by: hujun5 --- sched/pthread/pthread_mutex.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sched/pthread/pthread_mutex.c b/sched/pthread/pthread_mutex.c index 3bd5e62c9c9..7a790d3abb2 100644 --- a/sched/pthread/pthread_mutex.c +++ b/sched/pthread/pthread_mutex.c @@ -372,7 +372,7 @@ void pthread_mutex_inconsistent(FAR struct tcb_s *tcb) DEBUGASSERT(tcb != NULL); - flags = spin_lock_irqsave(&tcb->mhead_lock); + flags = spin_lock_irqsave_nopreempt(&tcb->mhead_lock); /* Remove and process each mutex held by this task */ @@ -390,5 +390,5 @@ void pthread_mutex_inconsistent(FAR struct tcb_s *tcb) mutex_unlock(&mutex->mutex); } - spin_unlock_irqrestore(&tcb->mhead_lock, flags); + spin_unlock_irqrestore_nopreempt(&tcb->mhead_lock, flags); }