From 27c925b9c8dfd5a9defa6838eab63f2d7fcf265e Mon Sep 17 00:00:00 2001 From: ChenRuiwei <1982833213@qq.com> Date: Mon, 7 Jul 2025 14:35:05 +0800 Subject: [PATCH] [pthreads] Fix pthread_cond_timedwait lacks timeout wakeup --- components/libc/posix/pthreads/pthread_cond.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/components/libc/posix/pthreads/pthread_cond.c b/components/libc/posix/pthreads/pthread_cond.c index 1241ef835dd..caedec7601c 100644 --- a/components/libc/posix/pthreads/pthread_cond.c +++ b/components/libc/posix/pthreads/pthread_cond.c @@ -367,30 +367,27 @@ rt_err_t _pthread_cond_timedwait(pthread_cond_t *cond, } { - register rt_base_t temp; struct rt_thread *thread; /* parameter check */ RT_ASSERT(sem != RT_NULL); RT_ASSERT(rt_object_get_type(&sem->parent.parent) == RT_Object_Class_Semaphore); - /* disable interrupt */ - temp = rt_hw_interrupt_disable(); + rt_enter_critical(); if (sem->value > 0) { /* semaphore is available */ sem->value--; - /* enable interrupt */ - rt_hw_interrupt_enable(temp); + rt_exit_critical(); } else { /* no waiting, return with timeout */ if (time == 0) { - rt_hw_interrupt_enable(temp); + rt_exit_critical(); return -RT_ETIMEOUT; } @@ -434,11 +431,8 @@ rt_err_t _pthread_cond_timedwait(pthread_cond_t *cond, return -RT_ERROR; } - /* enable interrupt */ - rt_hw_interrupt_enable(temp); - - /* do schedule */ - rt_schedule(); + /* exit critical and do schedule */ + rt_exit_critical(); result = thread->error;