pthread: pthread_cond_wait dead lock

pthread_cond_wait is preempted after releasing the lock, 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-14 09:28:28 +08:00 committed by Petro Karashchenko
parent 2be18a8b24
commit 0477fb116a
1 changed files with 3 additions and 2 deletions

View File

@ -58,6 +58,7 @@ int pthread_cond_wait(FAR pthread_cond_t *cond, FAR pthread_mutex_t *mutex)
{ {
int status; int status;
int ret; int ret;
irqstate_t flags;
sinfo("cond=%p mutex=%p\n", cond, mutex); sinfo("cond=%p mutex=%p\n", cond, mutex);
@ -92,7 +93,7 @@ int pthread_cond_wait(FAR pthread_cond_t *cond, FAR pthread_mutex_t *mutex)
sinfo("Give up mutex / take cond\n"); sinfo("Give up mutex / take cond\n");
sched_lock(); flags = enter_critical_section();
mutex->pid = INVALID_PROCESS_ID; mutex->pid = INVALID_PROCESS_ID;
#ifndef CONFIG_PTHREAD_MUTEX_UNSAFE #ifndef CONFIG_PTHREAD_MUTEX_UNSAFE
mflags = mutex->flags; mflags = mutex->flags;
@ -115,7 +116,7 @@ int pthread_cond_wait(FAR pthread_cond_t *cond, FAR pthread_mutex_t *mutex)
ret = status; ret = status;
} }
sched_unlock(); leave_critical_section(flags);
/* Reacquire the mutex. /* Reacquire the mutex.
* *