✨ feat: delete thread ref (#8456)
This commit is contained in:
parent
db2cfd335f
commit
6b6d39d716
|
@ -1127,7 +1127,6 @@ struct rt_thread
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
rt_atomic_t ref_count;
|
|
||||||
struct rt_spinlock spinlock;
|
struct rt_spinlock spinlock;
|
||||||
rt_ubase_t user_data; /**< private user data beyond this thread */
|
rt_ubase_t user_data; /**< private user data beyond this thread */
|
||||||
};
|
};
|
||||||
|
@ -1139,11 +1138,6 @@ typedef struct rt_thread *rt_thread_t;
|
||||||
|
|
||||||
/**@}*/
|
/**@}*/
|
||||||
|
|
||||||
#define rt_atomic_inc(v) rt_atomic_add((v), 1)
|
|
||||||
#define rt_atomic_dec(v) rt_atomic_sub((v), 1)
|
|
||||||
#define rt_get_thread_struct(object) do { rt_atomic_inc(&(object)->ref_count); } while(0)
|
|
||||||
#define rt_put_thread_struct(object) do { rt_atomic_dec(&(object)->ref_count); } while(0)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @addtogroup IPC
|
* @addtogroup IPC
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -99,20 +99,17 @@ void rt_tick_increase(void)
|
||||||
|
|
||||||
/* check time slice */
|
/* check time slice */
|
||||||
thread = rt_thread_self();
|
thread = rt_thread_self();
|
||||||
rt_get_thread_struct(thread);
|
|
||||||
level = rt_spin_lock_irqsave(&(thread->spinlock));
|
level = rt_spin_lock_irqsave(&(thread->spinlock));
|
||||||
rt_atomic_sub(&(thread->remaining_tick), 1);
|
rt_atomic_sub(&(thread->remaining_tick), 1);
|
||||||
if (rt_atomic_compare_exchange_strong(&(thread->remaining_tick), &oldval, thread->init_tick))
|
if (rt_atomic_compare_exchange_strong(&(thread->remaining_tick), &oldval, thread->init_tick))
|
||||||
{
|
{
|
||||||
thread->stat |= RT_THREAD_STAT_YIELD;
|
thread->stat |= RT_THREAD_STAT_YIELD;
|
||||||
rt_spin_unlock_irqrestore(&(thread->spinlock), level);
|
rt_spin_unlock_irqrestore(&(thread->spinlock), level);
|
||||||
rt_put_thread_struct(thread);
|
|
||||||
rt_schedule();
|
rt_schedule();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rt_spin_unlock_irqrestore(&(thread->spinlock), level);
|
rt_spin_unlock_irqrestore(&(thread->spinlock), level);
|
||||||
rt_put_thread_struct(thread);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check timer */
|
/* check timer */
|
||||||
|
|
|
@ -232,11 +232,8 @@ void rt_cpus_lock_status_restore(struct rt_thread *thread)
|
||||||
{
|
{
|
||||||
rt_schedule_insert_thread(pcpu->current_thread);
|
rt_schedule_insert_thread(pcpu->current_thread);
|
||||||
}
|
}
|
||||||
rt_put_thread_struct(pcpu->current_thread);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
pcpu->current_thread = thread;
|
pcpu->current_thread = thread;
|
||||||
rt_get_thread_struct(thread);
|
|
||||||
}
|
}
|
||||||
RTM_EXPORT(rt_cpus_lock_status_restore);
|
RTM_EXPORT(rt_cpus_lock_status_restore);
|
||||||
#endif /* RT_USING_SMP */
|
#endif /* RT_USING_SMP */
|
||||||
|
|
|
@ -209,10 +209,6 @@ static void rt_defunct_execute(void)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (rt_atomic_load(&(thread->ref_count)))
|
|
||||||
{
|
|
||||||
rt_thread_delay(5);
|
|
||||||
}
|
|
||||||
#ifdef RT_USING_MODULE
|
#ifdef RT_USING_MODULE
|
||||||
module = (struct rt_dlmodule*)thread->parent.module_id;
|
module = (struct rt_dlmodule*)thread->parent.module_id;
|
||||||
if (module)
|
if (module)
|
||||||
|
|
|
@ -291,7 +291,7 @@ static rt_err_t _thread_init(struct rt_thread *thread,
|
||||||
#ifdef RT_USING_MODULE
|
#ifdef RT_USING_MODULE
|
||||||
thread->parent.module_id = 0;
|
thread->parent.module_id = 0;
|
||||||
#endif /* RT_USING_MODULE */
|
#endif /* RT_USING_MODULE */
|
||||||
rt_atomic_store(&thread->ref_count, 0);
|
|
||||||
rt_spin_lock_init(&thread->spinlock);
|
rt_spin_lock_init(&thread->spinlock);
|
||||||
|
|
||||||
RT_OBJECT_HOOKLIST_CALL(rt_thread_inited, (thread));
|
RT_OBJECT_HOOKLIST_CALL(rt_thread_inited, (thread));
|
||||||
|
|
Loading…
Reference in New Issue