From 9cd8ff5a0b9514f344cf61d7fb272ddd31b3d6f1 Mon Sep 17 00:00:00 2001 From: hujun5 Date: Sun, 23 Apr 2023 17:08:18 +0800 Subject: [PATCH] pthread: sched_lock should replace with enter_critical_secion sched_lock cannot lock threads from other CPUs, use enter_critical_section Signed-off-by: hujun5 --- sched/pthread/pthread_mutexunlock.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sched/pthread/pthread_mutexunlock.c b/sched/pthread/pthread_mutexunlock.c index cef1487ef8..08b5b9e2e4 100644 --- a/sched/pthread/pthread_mutexunlock.c +++ b/sched/pthread/pthread_mutexunlock.c @@ -101,6 +101,7 @@ static inline bool pthread_mutex_islocked(FAR struct pthread_mutex_s *mutex) int pthread_mutex_unlock(FAR pthread_mutex_t *mutex) { int ret = EPERM; + irqstate_t flags; sinfo("mutex=%p\n", mutex); DEBUGASSERT(mutex != NULL); @@ -113,7 +114,7 @@ int pthread_mutex_unlock(FAR pthread_mutex_t *mutex) * This all needs to be one atomic action. */ - sched_lock(); + flags = enter_critical_section(); /* The unlock operation is only performed if the mutex is actually locked. * EPERM *must* be returned if the mutex type is PTHREAD_MUTEX_ERRORCHECK @@ -223,7 +224,7 @@ int pthread_mutex_unlock(FAR pthread_mutex_t *mutex) } } - sched_unlock(); + leave_critical_section(flags); sinfo("Returning %d\n", ret); return ret; }