Lines Matching refs:thread

74 static void thr_destroy(struct pthread *curthread, struct pthread *thread);
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_calloc(1, sizeof(struct pthread)); in _thr_alloc()
154 if (thread == NULL) { in _thr_alloc()
158 if ((thread->sleepqueue = _sleepq_alloc()) == NULL || in _thr_alloc()
159 (thread->wake_addr = _thr_alloc_wake_addr()) == NULL) { in _thr_alloc()
160 thr_destroy(curthread, thread); in _thr_alloc()
165 bzero(&thread->_pthread_startzero, in _thr_alloc()
170 tcb = _tcb_ctor(thread, 0 /* not initial tls */); in _thr_alloc()
173 tcb = _tcb_ctor(thread, 1 /* initial tls */); in _thr_alloc()
176 thread->tcb = tcb; in _thr_alloc()
178 thr_destroy(curthread, thread); in _thr_alloc()
180 thread = NULL; in _thr_alloc()
182 return (thread); in _thr_alloc()
186 _thr_free(struct pthread *curthread, struct pthread *thread) in _thr_free() argument
188 DBG_MSG("Freeing thread %p\n", thread); in _thr_free()
197 _tcb_dtor(thread->tcb); in _thr_free()
200 _tcb_dtor(thread->tcb); in _thr_free()
202 thread->tcb = NULL; in _thr_free()
204 thr_destroy(curthread, thread); in _thr_free()
212 TAILQ_INSERT_TAIL(&free_threadq, thread, tle); in _thr_free()
219 thr_destroy(struct pthread *curthread __unused, struct pthread *thread) in thr_destroy() argument
221 if (thread->sleepqueue != NULL) in thr_destroy()
222 _sleepq_free(thread->sleepqueue); in thr_destroy()
223 if (thread->wake_addr != NULL) in thr_destroy()
224 _thr_release_wake_addr(thread->wake_addr); in thr_destroy()
225 __thr_free(thread); in thr_destroy()
233 _thr_link(struct pthread *curthread, struct pthread *thread) in _thr_link() argument
236 THR_LIST_ADD(thread); in _thr_link()
245 _thr_unlink(struct pthread *curthread, struct pthread *thread) in _thr_unlink() argument
248 THR_LIST_REMOVE(thread); in _thr_unlink()
254 _thr_hash_add(struct pthread *thread) in _thr_hash_add() argument
258 head = &thr_hashtable[THREAD_HASH(thread)]; in _thr_hash_add()
259 LIST_INSERT_HEAD(head, thread, hle); in _thr_hash_add()
263 _thr_hash_remove(struct pthread *thread) in _thr_hash_remove() argument
265 LIST_REMOVE(thread, hle); in _thr_hash_remove()
269 _thr_hash_find(struct pthread *thread) in _thr_hash_find() argument
274 head = &thr_hashtable[THREAD_HASH(thread)]; in _thr_hash_find()
276 if (td == thread) in _thr_hash_find()
277 return (thread); in _thr_hash_find()
288 _thr_ref_add(struct pthread *curthread, struct pthread *thread, in _thr_ref_add() argument
293 if (thread == NULL) in _thr_ref_add()
297 if ((ret = _thr_find_thread(curthread, thread, include_dead)) == 0) { in _thr_ref_add()
298 thread->refcount++; in _thr_ref_add()
300 THR_THREAD_UNLOCK(curthread, thread); in _thr_ref_add()
308 _thr_ref_delete(struct pthread *curthread, struct pthread *thread) in _thr_ref_delete() argument
310 THR_THREAD_LOCK(curthread, thread); in _thr_ref_delete()
311 thread->refcount--; in _thr_ref_delete()
312 _thr_try_gc(curthread, thread); in _thr_ref_delete()
318 _thr_try_gc(struct pthread *curthread, struct pthread *thread) in _thr_try_gc() argument
320 if (THR_SHOULD_GC(thread)) { in _thr_try_gc()
321 THR_REF_ADD(curthread, thread); in _thr_try_gc()
322 THR_THREAD_UNLOCK(curthread, thread); in _thr_try_gc()
324 THR_THREAD_LOCK(curthread, thread); in _thr_try_gc()
325 THR_REF_DEL(curthread, thread); in _thr_try_gc()
326 if (THR_SHOULD_GC(thread)) { in _thr_try_gc()
327 THR_LIST_REMOVE(thread); in _thr_try_gc()
328 THR_GCLIST_ADD(thread); in _thr_try_gc()
330 THR_THREAD_UNLOCK(curthread, thread); in _thr_try_gc()
333 THR_THREAD_UNLOCK(curthread, thread); in _thr_try_gc()
339 _thr_find_thread(struct pthread *curthread, struct pthread *thread, in _thr_find_thread() argument
345 if (thread == NULL) in _thr_find_thread()
350 pthread = _thr_hash_find(thread); in _thr_find_thread()