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 <hujun5@xiaomi.com>
This commit is contained in:
hujun5 2023-04-23 17:08:18 +08:00 committed by Xiang Xiao
parent 447a0bce95
commit 9cd8ff5a0b

View File

@ -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 pthread_mutex_unlock(FAR pthread_mutex_t *mutex)
{ {
int ret = EPERM; int ret = EPERM;
irqstate_t flags;
sinfo("mutex=%p\n", mutex); sinfo("mutex=%p\n", mutex);
DEBUGASSERT(mutex != NULL); DEBUGASSERT(mutex != NULL);
@ -113,7 +114,7 @@ int pthread_mutex_unlock(FAR pthread_mutex_t *mutex)
* This all needs to be one atomic action. * 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. /* The unlock operation is only performed if the mutex is actually locked.
* EPERM *must* be returned if the mutex type is PTHREAD_MUTEX_ERRORCHECK * 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); sinfo("Returning %d\n", ret);
return ret; return ret;
} }