From 204c810ca1336c86109c6311810a6cf6b67dfb2c Mon Sep 17 00:00:00 2001 From: weidongshan Date: Mon, 12 Jun 2023 11:46:22 +0800 Subject: [PATCH] fix bug: thread suspened can't handle signal --- src/signal.c | 88 ++++++++++++++++++++++++---------------------------- 1 file changed, 40 insertions(+), 48 deletions(-) diff --git a/src/signal.c b/src/signal.c index 51f92fbde4..3677ff930e 100644 --- a/src/signal.c +++ b/src/signal.c @@ -103,73 +103,65 @@ static void _signal_deliver(rt_thread_t tid) return; } - if ((tid->stat & RT_THREAD_SUSPEND_MASK) == RT_THREAD_SUSPEND_MASK) + if (tid == rt_thread_self()) { - /* resume thread to handle signal */ -#ifdef RT_USING_SMART - rt_thread_wakeup(tid); -#else - rt_thread_resume(tid); -#endif /* add signal state */ - tid->stat |= (RT_THREAD_STAT_SIGNAL | RT_THREAD_STAT_SIGNAL_PENDING); + tid->stat |= RT_THREAD_STAT_SIGNAL; rt_hw_interrupt_enable(level); - /* re-schedule */ - rt_schedule(); + /* do signal action in self thread context */ + if (rt_interrupt_get_nest() == 0) + { + rt_thread_handle_sig(RT_TRUE); + } } - else + else if (!((tid->stat & RT_THREAD_STAT_SIGNAL_MASK) & RT_THREAD_STAT_SIGNAL)) { - if (tid == rt_thread_self()) + + if ((tid->stat & RT_THREAD_SUSPEND_MASK) == RT_THREAD_SUSPEND_MASK) { - /* add signal state */ - tid->stat |= RT_THREAD_STAT_SIGNAL; + /* resume thread to handle signal */ +#ifdef RT_USING_SMART + rt_thread_wakeup(tid); +#else + rt_thread_resume(tid); +#endif + } - rt_hw_interrupt_enable(level); + /* add signal state */ + tid->stat |= (RT_THREAD_STAT_SIGNAL | RT_THREAD_STAT_SIGNAL_PENDING); - /* do signal action in self thread context */ - if (rt_interrupt_get_nest() == 0) - { - rt_thread_handle_sig(RT_TRUE); - } - } - else if (!((tid->stat & RT_THREAD_STAT_SIGNAL_MASK) & RT_THREAD_STAT_SIGNAL)) +#ifdef RT_USING_SMP { - /* add signal state */ - tid->stat |= (RT_THREAD_STAT_SIGNAL | RT_THREAD_STAT_SIGNAL_PENDING); + int cpu_id; -#ifdef RT_USING_SMP + cpu_id = tid->oncpu; + if ((cpu_id != RT_CPU_DETACHED) && (cpu_id != rt_hw_cpu_id())) { - int cpu_id; + rt_uint32_t cpu_mask; - cpu_id = tid->oncpu; - if ((cpu_id != RT_CPU_DETACHED) && (cpu_id != rt_hw_cpu_id())) - { - rt_uint32_t cpu_mask; - - cpu_mask = RT_CPU_MASK ^ (1 << cpu_id); - rt_hw_ipi_send(RT_SCHEDULE_IPI, cpu_mask); - } + cpu_mask = RT_CPU_MASK ^ (1 << cpu_id); + rt_hw_ipi_send(RT_SCHEDULE_IPI, cpu_mask); } + } #else - /* point to the signal handle entry */ - tid->stat &= ~RT_THREAD_STAT_SIGNAL_PENDING; - tid->sig_ret = tid->sp; - tid->sp = rt_hw_stack_init((void *)_signal_entry, RT_NULL, - (void *)((char *)tid->sig_ret - 32), RT_NULL); + /* point to the signal handle entry */ + tid->stat &= ~RT_THREAD_STAT_SIGNAL_PENDING; + tid->sig_ret = tid->sp; + tid->sp = rt_hw_stack_init((void *)_signal_entry, RT_NULL, + (void *)((char *)tid->sig_ret - 32), RT_NULL); #endif /* RT_USING_SMP */ - rt_hw_interrupt_enable(level); - LOG_D("signal stack pointer @ 0x%08x", tid->sp); + rt_hw_interrupt_enable(level); + LOG_D("signal stack pointer @ 0x%08x", tid->sp); - /* re-schedule */ - rt_schedule(); - } - else - { - rt_hw_interrupt_enable(level); - } + /* re-schedule */ + rt_schedule(); + } + else + { + rt_hw_interrupt_enable(level); } } -- Gitee