* @brief This function will perform system background job when system idle. */
| 65 | * @brief This function will perform system background job when system idle. |
| 66 | */ |
| 67 | void rt_defunct_execute(void) |
| 68 | { |
| 69 | /* Loop until there is no dead thread. So one call to rt_defunct_execute |
| 70 | * will do all the cleanups. */ |
| 71 | while (1) |
| 72 | { |
| 73 | rt_thread_t thread; |
| 74 | rt_bool_t object_is_systemobject; |
| 75 | void (*cleanup)(struct rt_thread *tid); |
| 76 | |
| 77 | #ifdef RT_USING_MODULE |
| 78 | struct rt_dlmodule *module = RT_NULL; |
| 79 | #endif |
| 80 | /* get defunct thread */ |
| 81 | thread = rt_thread_defunct_dequeue(); |
| 82 | if (thread == RT_NULL) |
| 83 | { |
| 84 | break; |
| 85 | } |
| 86 | |
| 87 | #ifdef RT_USING_MODULE |
| 88 | module = (struct rt_dlmodule *)thread->parent.module_id; |
| 89 | if (module) |
| 90 | { |
| 91 | dlmodule_destroy(module); |
| 92 | } |
| 93 | #endif |
| 94 | |
| 95 | #ifdef RT_USING_SIGNALS |
| 96 | rt_thread_free_sig(thread); |
| 97 | #endif |
| 98 | |
| 99 | /* store the point of "thread->cleanup" avoid to lose */ |
| 100 | cleanup = thread->cleanup; |
| 101 | |
| 102 | /* if it's a system object, detach it */ |
| 103 | object_is_systemobject = rt_object_is_systemobject((rt_object_t)thread); |
| 104 | if (object_is_systemobject == RT_TRUE) |
| 105 | { |
| 106 | /* detach this object */ |
| 107 | rt_object_detach((rt_object_t)thread); |
| 108 | } |
| 109 | |
| 110 | /* invoke thread cleanup */ |
| 111 | if (cleanup != RT_NULL) |
| 112 | { |
| 113 | cleanup(thread); |
| 114 | } |
| 115 | |
| 116 | #ifdef RT_USING_HEAP |
| 117 | #ifdef RT_USING_MEM_PROTECTION |
| 118 | if (thread->mem_regions != RT_NULL) |
| 119 | { |
| 120 | RT_KERNEL_FREE(thread->mem_regions); |
| 121 | } |
| 122 | #endif |
| 123 | /* if need free, delete it */ |
| 124 | if (object_is_systemobject == RT_FALSE) |
no test coverage detected