* @brief Releases a thread ID (TID) and associated resources * * @param[in] tid The thread ID to release * * @note This function performs thread-safe release of a TID by: * 1. Finding the TID in the AVL tree and removing it * 2. Adding the freed TID structure to the free list for reuse * 3. Handling thread reference counting and potential suspension */
| 126 | * 3. Handling thread reference counting and potential suspension |
| 127 | */ |
| 128 | void lwp_tid_put(int tid) |
| 129 | { |
| 130 | struct lwp_avl_struct *p; |
| 131 | rt_thread_t thread; |
| 132 | rt_thread_t current; |
| 133 | |
| 134 | lwp_mutex_take_safe(&tid_lock, RT_WAITING_FOREVER, 0); |
| 135 | p = lwp_avl_find(tid, lwp_tid_root); |
| 136 | if (p) |
| 137 | { |
| 138 | thread = p->data; |
| 139 | p->data = RT_NULL; |
| 140 | lwp_avl_remove(p, &lwp_tid_root); |
| 141 | p->avl_right = lwp_tid_free_head; |
| 142 | lwp_tid_free_head = p; |
| 143 | } |
| 144 | else |
| 145 | thread = RT_NULL; |
| 146 | |
| 147 | if (thread && thread->tid_ref_count) |
| 148 | { |
| 149 | current = rt_thread_self(); |
| 150 | RT_ASSERT(thread->susp_recycler == RT_NULL); |
| 151 | thread->susp_recycler = current; |
| 152 | |
| 153 | rt_enter_critical(); |
| 154 | rt_thread_suspend_with_flag(current, RT_UNINTERRUPTIBLE); |
| 155 | lwp_mutex_release_safe(&tid_lock); |
| 156 | rt_exit_critical(); |
| 157 | |
| 158 | rt_schedule(); |
| 159 | } |
| 160 | else |
| 161 | lwp_mutex_release_safe(&tid_lock); |
| 162 | } |
| 163 | |
| 164 | /** |
| 165 | * @brief Retrieves the thread object associated with a thread ID (TID) |
no test coverage detected