[modify] the recycle logic about resource of pthread.

This commit is contained in:
liuxianliang
2022-05-18 08:44:30 +08:00
committed by guo
parent 9ab2094ef6
commit 9f5a9b6bc8
3 changed files with 120 additions and 109 deletions
+16 -9
View File
@@ -194,6 +194,7 @@ static void rt_defunct_execute(void)
while (1)
{
rt_thread_t thread;
rt_bool_t object_is_systemobject;
void (*cleanup)(struct rt_thread *tid);
#ifdef RT_USING_MODULE
@@ -212,32 +213,38 @@ static void rt_defunct_execute(void)
dlmodule_destroy(module);
}
#endif
/* invoke thread cleanup */
cleanup = thread->cleanup;
if (cleanup != RT_NULL)
{
cleanup(thread);
}
#ifdef RT_USING_SIGNALS
rt_thread_free_sig(thread);
#endif
/* store the point of "thread->cleanup" avoid to lose */
cleanup = thread->cleanup;
/* if it's a system object, not delete it */
if (rt_object_is_systemobject((rt_object_t)thread) == RT_TRUE)
object_is_systemobject = rt_object_is_systemobject((rt_object_t)thread);
if (object_is_systemobject == RT_TRUE)
{
/* detach this object */
rt_object_detach((rt_object_t)thread);
}
else
/* invoke thread cleanup */
if (cleanup != RT_NULL)
{
cleanup(thread);
}
#ifdef RT_USING_HEAP
/* if need free, delete it */
if (object_is_systemobject == RT_FALSE)
{
/* release thread's stack */
RT_KERNEL_FREE(thread->stack_addr);
/* delete thread object */
rt_object_delete((rt_object_t)thread);
#endif
}
#endif
}
}