Skip to content

Commit 4db9cfb

Browse files
thewon86Guozhanxin
authored andcommitted
return thread error when resumed by signal
1 parent 3e59cfd commit 4db9cfb

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

components/drivers/ipc/waitqueue.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Date Author Notes
88
* 2018/06/26 Bernard Fix the wait queue issue when wakeup a soon
99
* to blocked thread.
10+
* 2022-01-24 THEWON let rt_wqueue_wait return thread->error when using signal
1011
*/
1112

1213
#include <stdint.h>
@@ -141,6 +142,10 @@ int rt_wqueue_wait(rt_wqueue_t *queue, int condition, int msec)
141142
rt_list_init(&__wait.list);
142143

143144
level = rt_hw_interrupt_disable();
145+
146+
/* reset thread error */
147+
tid->error = RT_EOK;
148+
144149
if (queue->flag == RT_WQ_FLAG_WAKEUP)
145150
{
146151
/* already wakeup */
@@ -171,5 +176,5 @@ int rt_wqueue_wait(rt_wqueue_t *queue, int condition, int msec)
171176

172177
rt_wqueue_remove(&__wait);
173178

174-
return 0;
179+
return tid->error;
175180
}

src/ipc.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
* 2021-01-03 Meco Man implement rt_mb_urgent()
4141
* 2021-05-30 Meco Man implement rt_mutex_trytake()
4242
* 2022-01-07 Gabriel Moving __on_rt_xxxxx_hook to ipc.c
43+
* 2022-01-24 THEWON let rt_mutex_take return thread->error when using signal
4344
*/
4445

4546
#include <rtthread.h>
@@ -947,9 +948,6 @@ rt_err_t rt_mutex_take(rt_mutex_t mutex, rt_int32_t time)
947948
}
948949
else
949950
{
950-
#ifdef RT_USING_SIGNALS
951-
__again:
952-
#endif /* RT_USING_SIGNALS */
953951
/* The value of mutex is 1 in initial status. Therefore, if the
954952
* value is great than 0, it indicates the mutex is avaible.
955953
*/
@@ -1026,11 +1024,6 @@ rt_err_t rt_mutex_take(rt_mutex_t mutex, rt_int32_t time)
10261024

10271025
if (thread->error != RT_EOK)
10281026
{
1029-
#ifdef RT_USING_SIGNALS
1030-
/* interrupt by signal, try it again */
1031-
if (thread->error == -RT_EINTR) goto __again;
1032-
#endif /* RT_USING_SIGNALS */
1033-
10341027
/* return error */
10351028
return thread->error;
10361029
}

src/thread.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
* 2021-11-15 THEWON Remove duplicate work between idle and _thread_exit
3131
* 2021-12-27 Meco Man remove .init_priority
3232
* 2022-01-07 Gabriel Moving __on_rt_xxxxx_hook to thread.c
33+
* 2022-01-24 THEWON let rt_thread_sleep return thread->error when using signal
3334
*/
3435

3536
#include <rthw.h>
@@ -566,6 +567,9 @@ rt_err_t rt_thread_sleep(rt_tick_t tick)
566567
/* disable interrupt */
567568
temp = rt_hw_interrupt_disable();
568569

570+
/* reset thread error */
571+
thread->error = RT_EOK;
572+
569573
/* suspend thread */
570574
rt_thread_suspend(thread);
571575

@@ -582,7 +586,7 @@ rt_err_t rt_thread_sleep(rt_tick_t tick)
582586
if (thread->error == -RT_ETIMEOUT)
583587
thread->error = RT_EOK;
584588

585-
return RT_EOK;
589+
return thread->error;
586590
}
587591

588592
/**
@@ -625,6 +629,9 @@ rt_err_t rt_thread_delay_until(rt_tick_t *tick, rt_tick_t inc_tick)
625629
/* disable interrupt */
626630
level = rt_hw_interrupt_disable();
627631

632+
/* reset thread error */
633+
thread->error = RT_EOK;
634+
628635
cur_tick = rt_tick_get();
629636
if (cur_tick - *tick < inc_tick)
630637
{
@@ -657,7 +664,7 @@ rt_err_t rt_thread_delay_until(rt_tick_t *tick, rt_tick_t inc_tick)
657664
rt_hw_interrupt_enable(level);
658665
}
659666

660-
return RT_EOK;
667+
return thread->error;
661668
}
662669
RTM_EXPORT(rt_thread_delay_until);
663670

0 commit comments

Comments
 (0)