Lines Matching full:thread

75 static void thr_destroy(struct pthread *curthread, struct pthread *thread);
120 * XXX we don't free initial thread, because there might in _thr_gc()
121 * have some code referencing initial thread. in _thr_gc()
124 DBG_MSG("Initial thread won't be freed\n"); in _thr_gc()
135 struct pthread *thread = NULL; in _thr_alloc() local
143 if ((thread = TAILQ_FIRST(&free_threadq)) != NULL) { in _thr_alloc()
144 TAILQ_REMOVE(&free_threadq, thread, tle); in _thr_alloc()
150 if (thread == NULL) { in _thr_alloc()
154 thread = __thr_aligned_alloc_offset(_Alignof(struct pthread), in _thr_alloc()
156 if (thread == NULL) { in _thr_alloc()
160 memset(thread, 0, sizeof(*thread)); in _thr_alloc()
161 if ((thread->sleepqueue = _sleepq_alloc()) == NULL || in _thr_alloc()
162 (thread->wake_addr = _thr_alloc_wake_addr()) == NULL) { in _thr_alloc()
163 thr_destroy(curthread, thread); in _thr_alloc()
168 bzero(&thread->_pthread_startzero, in _thr_alloc()
173 tcb = _tcb_ctor(thread, 0 /* not initial tls */); in _thr_alloc()
176 tcb = _tcb_ctor(thread, 1 /* initial tls */); in _thr_alloc()
179 thread->tcb = tcb; in _thr_alloc()
181 thr_destroy(curthread, thread); in _thr_alloc()
183 thread = NULL; in _thr_alloc()
185 return (thread); in _thr_alloc()
189 _thr_free(struct pthread *curthread, struct pthread *thread) in _thr_free() argument
191 DBG_MSG("Freeing thread %p\n", thread); in _thr_free()
200 _tcb_dtor(thread->tcb); in _thr_free()
203 _tcb_dtor(thread->tcb); in _thr_free()
205 thread->tcb = NULL; in _thr_free()
207 thr_destroy(curthread, thread); in _thr_free()
211 * Add the thread to the free thread list, this also avoids in _thr_free()
215 TAILQ_INSERT_TAIL(&free_threadq, thread, tle); in _thr_free()
222 thr_destroy(struct pthread *curthread __unused, struct pthread *thread) in thr_destroy() argument
224 if (thread->sleepqueue != NULL) in thr_destroy()
225 _sleepq_free(thread->sleepqueue); in thr_destroy()
226 if (thread->wake_addr != NULL) in thr_destroy()
227 _thr_release_wake_addr(thread->wake_addr); in thr_destroy()
228 __thr_free(thread); in thr_destroy()
232 * Add the thread to the list of all threads and increment
236 _thr_link(struct pthread *curthread, struct pthread *thread) in _thr_link() argument
239 THR_LIST_ADD(thread); in _thr_link()
245 * Remove an active thread.
248 _thr_unlink(struct pthread *curthread, struct pthread *thread) in _thr_unlink() argument
251 THR_LIST_REMOVE(thread); in _thr_unlink()
257 _thr_hash_add(struct pthread *thread) in _thr_hash_add() argument
261 head = &thr_hashtable[THREAD_HASH(thread)]; in _thr_hash_add()
262 LIST_INSERT_HEAD(head, thread, hle); in _thr_hash_add()
266 _thr_hash_remove(struct pthread *thread) in _thr_hash_remove() argument
268 LIST_REMOVE(thread, hle); in _thr_hash_remove()
272 _thr_hash_find(struct pthread *thread) in _thr_hash_find() argument
277 head = &thr_hashtable[THREAD_HASH(thread)]; in _thr_hash_find()
279 if (td == thread) in _thr_hash_find()
280 return (thread); in _thr_hash_find()
286 * Find a thread in the linked list of active threads and add a reference
291 _thr_ref_add(struct pthread *curthread, struct pthread *thread, in _thr_ref_add() argument
296 if (thread == NULL) in _thr_ref_add()
297 /* Invalid thread: */ in _thr_ref_add()
300 if ((ret = _thr_find_thread(curthread, thread, include_dead)) == 0) { in _thr_ref_add()
301 thread->refcount++; in _thr_ref_add()
303 THR_THREAD_UNLOCK(curthread, thread); in _thr_ref_add()
306 /* Return zero if the thread exists: */ in _thr_ref_add()
311 _thr_ref_delete(struct pthread *curthread, struct pthread *thread) in _thr_ref_delete() argument
313 THR_THREAD_LOCK(curthread, thread); in _thr_ref_delete()
314 thread->refcount--; in _thr_ref_delete()
315 _thr_try_gc(curthread, thread); in _thr_ref_delete()
319 /* entered with thread lock held, exit with thread lock released */
321 _thr_try_gc(struct pthread *curthread, struct pthread *thread) in _thr_try_gc() argument
323 if (THR_SHOULD_GC(thread)) { in _thr_try_gc()
324 THR_REF_ADD(curthread, thread); in _thr_try_gc()
325 THR_THREAD_UNLOCK(curthread, thread); in _thr_try_gc()
327 THR_THREAD_LOCK(curthread, thread); in _thr_try_gc()
328 THR_REF_DEL(curthread, thread); in _thr_try_gc()
329 if (THR_SHOULD_GC(thread)) { in _thr_try_gc()
330 THR_LIST_REMOVE(thread); in _thr_try_gc()
331 THR_GCLIST_ADD(thread); in _thr_try_gc()
333 THR_THREAD_UNLOCK(curthread, thread); in _thr_try_gc()
336 THR_THREAD_UNLOCK(curthread, thread); in _thr_try_gc()
340 /* return with thread lock held if thread is found */
342 _thr_find_thread(struct pthread *curthread, struct pthread *thread, in _thr_find_thread() argument
348 if (thread == NULL) in _thr_find_thread()
353 pthread = _thr_hash_find(thread); in _thr_find_thread()