🐞 fix(src/idle.c): fix thread exit (#8239)

This commit is contained in:
xqyjlj 2023-11-13 22:46:48 +08:00 committed by GitHub
parent 9acebb07dc
commit 3aa19af301
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 7 deletions

View File

@ -17,6 +17,7 @@
* combine the code of primary and secondary cpu
* 2021-11-15 THEWON Remove duplicate work between idle and _thread_exit
* 2023-09-15 xqyjlj perf rt_hw_interrupt_disable/enable
* 2023-11-07 xqyjlj fix thread exit
*/
#include <rthw.h>
@ -43,7 +44,7 @@
#define _CPUS_NR RT_CPUS_NR
static rt_list_t _rt_thread_defunct = RT_LIST_OBJECT_INIT(_rt_thread_defunct);
static struct rt_mutex _defunct_mutex;
static struct rt_spinlock _spinlock = RT_SPINLOCK_INIT;
static rt_atomic_t _idle_inited = 0;
static struct rt_thread idle_thread[_CPUS_NR];
rt_align(RT_ALIGN_SIZE)
@ -130,13 +131,14 @@ rt_err_t rt_thread_idle_delhook(void (*hook)(void))
*/
void rt_thread_defunct_enqueue(rt_thread_t thread)
{
rt_base_t level;
if (rt_atomic_load(&_idle_inited) == 0)
{
return;
}
rt_mutex_take(&_defunct_mutex, RT_WAITING_FOREVER);
level = rt_spin_lock_irqsave(&_spinlock);
rt_list_insert_after(&_rt_thread_defunct, &thread->tlist);
rt_mutex_release(&_defunct_mutex);
rt_spin_unlock_irqrestore(&_spinlock, level);
#ifdef RT_USING_SMP
rt_sem_release(&system_sem);
#endif
@ -152,7 +154,7 @@ rt_thread_t rt_thread_defunct_dequeue(void)
rt_list_t *l = &_rt_thread_defunct;
#ifdef RT_USING_SMP
rt_mutex_take(&_defunct_mutex, RT_WAITING_FOREVER);
level = rt_spin_lock_irqsave(&_spinlock);
if (l->next != l)
{
thread = rt_list_entry(l->next,
@ -160,8 +162,7 @@ rt_thread_t rt_thread_defunct_dequeue(void)
tlist);
rt_list_remove(&(thread->tlist));
}
rt_mutex_release(&_defunct_mutex);
RT_UNUSED(level);
rt_spin_unlock_irqrestore(&_spinlock, level);
#else
if (l->next != l)
{
@ -364,7 +365,7 @@ void rt_thread_idle_init(void)
/* startup */
rt_thread_startup(&rt_system_thread);
#endif
rt_mutex_init(&_defunct_mutex, "defunct_mutex", RT_IPC_FLAG_FIFO);
rt_spin_lock_init(&_spinlock);
rt_atomic_store(&(_idle_inited), 1);
}