Skip to content

Commit 270ddb7

Browse files
author
ruiweichen
committed
[pthreads] Fix pthread_cond_timedwait lacks timeout wakeup
1 parent a1e8651 commit 270ddb7

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

components/libc/posix/pthreads/pthread_cond.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -367,30 +367,27 @@ rt_err_t _pthread_cond_timedwait(pthread_cond_t *cond,
367367
}
368368

369369
{
370-
register rt_base_t temp;
371370
struct rt_thread *thread;
372371

373372
/* parameter check */
374373
RT_ASSERT(sem != RT_NULL);
375374
RT_ASSERT(rt_object_get_type(&sem->parent.parent) == RT_Object_Class_Semaphore);
376375

377-
/* disable interrupt */
378-
temp = rt_hw_interrupt_disable();
376+
rt_enter_critical();
379377

380378
if (sem->value > 0)
381379
{
382380
/* semaphore is available */
383381
sem->value--;
384382

385-
/* enable interrupt */
386-
rt_hw_interrupt_enable(temp);
383+
rt_exit_critical();
387384
}
388385
else
389386
{
390387
/* no waiting, return with timeout */
391388
if (time == 0)
392389
{
393-
rt_hw_interrupt_enable(temp);
390+
rt_exit_critical();
394391

395392
return -RT_ETIMEOUT;
396393
}
@@ -434,11 +431,8 @@ rt_err_t _pthread_cond_timedwait(pthread_cond_t *cond,
434431
return -RT_ERROR;
435432
}
436433

437-
/* enable interrupt */
438-
rt_hw_interrupt_enable(temp);
439-
440-
/* do schedule */
441-
rt_schedule();
434+
/* exit critical and do schedule */
435+
rt_exit_critical();
442436

443437
result = thread->error;
444438

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy