MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / lwp_tid_put

Function lwp_tid_put

components/lwp/lwp_tid.c:128–162  ·  view source on GitHub ↗

* @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 */

Source from the content-addressed store, hash-verified

126 * 3. Handling thread reference counting and potential suspension
127 */
128void 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)

Callers 6

_thread_exitFunction · 0.85
_wait_sibling_exitFunction · 0.85
lwp_execveFunction · 0.85
sys_thread_createFunction · 0.85
_sys_cloneFunction · 0.85
_sys_forkFunction · 0.85

Calls 9

lwp_mutex_take_safeFunction · 0.85
lwp_avl_findFunction · 0.85
lwp_avl_removeFunction · 0.85
rt_thread_selfFunction · 0.85
lwp_mutex_release_safeFunction · 0.85
rt_enter_criticalFunction · 0.50
rt_exit_criticalFunction · 0.50
rt_scheduleFunction · 0.50

Tested by

no test coverage detected