Lines Matching full:thread

74 static void thr_destroy(struct pthread *curthread, struct pthread *thread);
119 * XXX we don't free initial thread, because there might in _thr_gc()
120 * have some code referencing initial thread. in _thr_gc()
123 DBG_MSG("Initial thread won't be freed\n"); in _thr_gc()
134 struct pthread *thread = NULL; in _thr_alloc() local
142 if ((thread = TAILQ_FIRST(&free_threadq)) != NULL) { in _thr_alloc()
143 TAILQ_REMOVE(&free_threadq, thread, tle); in _thr_alloc()
149 if (thread == NULL) { in _thr_alloc()
153 thread = __thr_aligned_alloc_offset(_Alignof(struct pthread), in _thr_alloc()
155 if (thread == NULL) { in _thr_alloc()
159 memset(thread, 0, sizeof(*thread)); in _thr_alloc()
160 if ((thread->sleepqueue = _sleepq_alloc()) == NULL || in _thr_alloc()
161 (thread->wake_addr = _thr_alloc_wake_addr()) == NULL) { in _thr_alloc()
162 thr_destroy(curthread, thread); in _thr_alloc()
167 bzero(&thread->_pthread_startzero, in _thr_alloc()
172 tcb = _tcb_ctor(thread, 0 /* not initial tls */); in _thr_alloc()
175 tcb = _tcb_ctor(thread, 1 /* initial tls */); in _thr_alloc()
178 thread->tcb = tcb; in _thr_alloc()
180 thr_destroy(curthread, thread); in _thr_alloc()
182 thread = NULL; in _thr_alloc()
184 return (thread); in _thr_alloc()
188 _thr_free(struct pthread *curthread, struct pthread *thread) in _thr_free() argument
190 DBG_MSG("Freeing thread %p\n", thread); in _thr_free()
199 _tcb_dtor(thread->tcb); in _thr_free()
202 _tcb_dtor(thread->tcb); in _thr_free()
204 thread->tcb = NULL; in _thr_free()
206 thr_destroy(curthread, thread); in _thr_free()
210 * Add the thread to the free thread list, this also avoids in _thr_free()
214 TAILQ_INSERT_TAIL(&free_threadq, thread, tle); in _thr_free()
221 thr_destroy(struct pthread *curthread __unused, struct pthread *thread) in thr_destroy() argument
223 if (thread->sleepqueue != NULL) in thr_destroy()
224 _sleepq_free(thread->sleepqueue); in thr_destroy()
225 if (thread->wake_addr != NULL) in thr_destroy()
226 _thr_release_wake_addr(thread->wake_addr); in thr_destroy()
227 __thr_free(thread); in thr_destroy()
231 * Add the thread to the list of all threads and increment
235 _thr_link(struct pthread *curthread, struct pthread *thread) in _thr_link() argument
238 THR_LIST_ADD(thread); in _thr_link()
244 * Remove an active thread.
247 _thr_unlink(struct pthread *curthread, struct pthread *thread) in _thr_unlink() argument
250 THR_LIST_REMOVE(thread); in _thr_unlink()
256 _thr_hash_add(struct pthread *thread) in _thr_hash_add() argument
260 head = &thr_hashtable[THREAD_HASH(thread)]; in _thr_hash_add()
261 LIST_INSERT_HEAD(head, thread, hle); in _thr_hash_add()
265 _thr_hash_remove(struct pthread *thread) in _thr_hash_remove() argument
267 LIST_REMOVE(thread, hle); in _thr_hash_remove()
271 _thr_hash_find(struct pthread *thread) in _thr_hash_find() argument
276 head = &thr_hashtable[THREAD_HASH(thread)]; in _thr_hash_find()
278 if (td == thread) in _thr_hash_find()
279 return (thread); in _thr_hash_find()
285 * Find a thread in the linked list of active threads and add a reference
290 _thr_ref_add(struct pthread *curthread, struct pthread *thread, in _thr_ref_add() argument
295 if (thread == NULL) in _thr_ref_add()
296 /* Invalid thread: */ in _thr_ref_add()
299 if ((ret = _thr_find_thread(curthread, thread, include_dead)) == 0) { in _thr_ref_add()
300 thread->refcount++; in _thr_ref_add()
302 THR_THREAD_UNLOCK(curthread, thread); in _thr_ref_add()
305 /* Return zero if the thread exists: */ in _thr_ref_add()
310 _thr_ref_delete(struct pthread *curthread, struct pthread *thread) in _thr_ref_delete() argument
312 THR_THREAD_LOCK(curthread, thread); in _thr_ref_delete()
313 thread->refcount--; in _thr_ref_delete()
314 _thr_try_gc(curthread, thread); in _thr_ref_delete()
318 /* entered with thread lock held, exit with thread lock released */
320 _thr_try_gc(struct pthread *curthread, struct pthread *thread) in _thr_try_gc() argument
322 if (THR_SHOULD_GC(thread)) { in _thr_try_gc()
323 THR_REF_ADD(curthread, thread); in _thr_try_gc()
324 THR_THREAD_UNLOCK(curthread, thread); in _thr_try_gc()
326 THR_THREAD_LOCK(curthread, thread); in _thr_try_gc()
327 THR_REF_DEL(curthread, thread); in _thr_try_gc()
328 if (THR_SHOULD_GC(thread)) { in _thr_try_gc()
329 THR_LIST_REMOVE(thread); in _thr_try_gc()
330 THR_GCLIST_ADD(thread); in _thr_try_gc()
332 THR_THREAD_UNLOCK(curthread, thread); in _thr_try_gc()
335 THR_THREAD_UNLOCK(curthread, thread); in _thr_try_gc()
339 /* return with thread lock held if thread is found */
341 _thr_find_thread(struct pthread *curthread, struct pthread *thread, in _thr_find_thread() argument
347 if (thread == NULL) in _thr_find_thread()
352 pthread = _thr_hash_find(thread); in _thr_find_thread()