summaryrefslogtreecommitdiff
path: root/src/idle.c
diff options
context:
space:
mode:
authorliuxianliang <[email protected]>2022-05-10 21:51:30 +0800
committerguo <[email protected]>2022-05-18 08:44:30 +0800
commit9f5a9b6bc884ff0640219677e2e18c84db2100c6 (patch)
tree25a4a7521a462c7bfee8e6ef5d1b265c7eb7de0e /src/idle.c
parent9ab2094ef613873ed86fb5fe675691f7d47a856c (diff)
[modify] the recycle logic about resource of pthread.
Diffstat (limited to 'src/idle.c')
-rw-r--r--src/idle.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/src/idle.c b/src/idle.c
index 4d147a297a..4b8a002942 100644
--- a/src/idle.c
+++ b/src/idle.c
@@ -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
}
}