Lines Matching refs:thread
75 static void thr_destroy(struct pthread *curthread, struct pthread *thread);
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 = calloc(1, sizeof(struct pthread)); in _thr_alloc()
155 if (thread == NULL) { in _thr_alloc()
159 if ((thread->sleepqueue = _sleepq_alloc()) == NULL || in _thr_alloc()
160 (thread->wake_addr = _thr_alloc_wake_addr()) == NULL) { in _thr_alloc()
161 thr_destroy(curthread, thread); in _thr_alloc()
166 bzero(&thread->_pthread_startzero, in _thr_alloc()
171 tcb = _tcb_ctor(thread, 0 /* not initial tls */); in _thr_alloc()
174 tcb = _tcb_ctor(thread, 1 /* initial tls */); in _thr_alloc()
177 thread->tcb = tcb; in _thr_alloc()
179 thr_destroy(curthread, thread); in _thr_alloc()
181 thread = NULL; in _thr_alloc()
183 return (thread); in _thr_alloc()
187 _thr_free(struct pthread *curthread, struct pthread *thread) in _thr_free() argument
189 DBG_MSG("Freeing thread %p\n", thread); in _thr_free()
198 _tcb_dtor(thread->tcb); in _thr_free()
201 _tcb_dtor(thread->tcb); in _thr_free()
203 thread->tcb = NULL; in _thr_free()
205 thr_destroy(curthread, thread); in _thr_free()
213 TAILQ_INSERT_TAIL(&free_threadq, thread, tle); in _thr_free()
220 thr_destroy(struct pthread *curthread __unused, struct pthread *thread) in thr_destroy() argument
222 if (thread->sleepqueue != NULL) in thr_destroy()
223 _sleepq_free(thread->sleepqueue); in thr_destroy()
224 if (thread->wake_addr != NULL) in thr_destroy()
225 _thr_release_wake_addr(thread->wake_addr); in thr_destroy()
226 free(thread); in thr_destroy()
234 _thr_link(struct pthread *curthread, struct pthread *thread) in _thr_link() argument
237 THR_LIST_ADD(thread); in _thr_link()
246 _thr_unlink(struct pthread *curthread, struct pthread *thread) in _thr_unlink() argument
249 THR_LIST_REMOVE(thread); in _thr_unlink()
255 _thr_hash_add(struct pthread *thread) in _thr_hash_add() argument
259 head = &thr_hashtable[THREAD_HASH(thread)]; in _thr_hash_add()
260 LIST_INSERT_HEAD(head, thread, hle); in _thr_hash_add()
264 _thr_hash_remove(struct pthread *thread) in _thr_hash_remove() argument
266 LIST_REMOVE(thread, hle); in _thr_hash_remove()
270 _thr_hash_find(struct pthread *thread) in _thr_hash_find() argument
275 head = &thr_hashtable[THREAD_HASH(thread)]; in _thr_hash_find()
277 if (td == thread) in _thr_hash_find()
278 return (thread); in _thr_hash_find()
289 _thr_ref_add(struct pthread *curthread, struct pthread *thread, in _thr_ref_add() argument
294 if (thread == NULL) in _thr_ref_add()
298 if ((ret = _thr_find_thread(curthread, thread, include_dead)) == 0) { in _thr_ref_add()
299 thread->refcount++; in _thr_ref_add()
301 THR_THREAD_UNLOCK(curthread, thread); in _thr_ref_add()
309 _thr_ref_delete(struct pthread *curthread, struct pthread *thread) in _thr_ref_delete() argument
311 THR_THREAD_LOCK(curthread, thread); in _thr_ref_delete()
312 thread->refcount--; in _thr_ref_delete()
313 _thr_try_gc(curthread, thread); in _thr_ref_delete()
319 _thr_try_gc(struct pthread *curthread, struct pthread *thread) in _thr_try_gc() argument
321 if (THR_SHOULD_GC(thread)) { in _thr_try_gc()
322 THR_REF_ADD(curthread, thread); in _thr_try_gc()
323 THR_THREAD_UNLOCK(curthread, thread); in _thr_try_gc()
325 THR_THREAD_LOCK(curthread, thread); in _thr_try_gc()
326 THR_REF_DEL(curthread, thread); in _thr_try_gc()
327 if (THR_SHOULD_GC(thread)) { in _thr_try_gc()
328 THR_LIST_REMOVE(thread); in _thr_try_gc()
329 THR_GCLIST_ADD(thread); in _thr_try_gc()
331 THR_THREAD_UNLOCK(curthread, thread); in _thr_try_gc()
334 THR_THREAD_UNLOCK(curthread, thread); in _thr_try_gc()
340 _thr_find_thread(struct pthread *curthread, struct pthread *thread, in _thr_find_thread() argument
346 if (thread == NULL) in _thr_find_thread()
351 pthread = _thr_hash_find(thread); in _thr_find_thread()