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
120 * have some code referencing initial thread.
123 DBG_MSG("Initial thread won't be freed\n");
134 struct pthread *thread = NULL;
142 if ((thread = TAILQ_FIRST(&free_threadq)) != NULL) {
143 TAILQ_REMOVE(&free_threadq, thread, tle);
149 if (thread == NULL) {
153 thread = __thr_calloc(1, sizeof(struct pthread));
154 if (thread == NULL) {
158 if ((thread->sleepqueue = _sleepq_alloc()) == NULL ||
159 (thread->wake_addr = _thr_alloc_wake_addr()) == NULL) {
160 thr_destroy(curthread, thread);
165 bzero(&thread->_pthread_startzero,
170 tcb = _tcb_ctor(thread, 0 /* not initial tls */);
173 tcb = _tcb_ctor(thread, 1 /* initial tls */);
176 thread->tcb = tcb;
178 thr_destroy(curthread, thread);
180 thread = NULL;
182 return (thread);
186 _thr_free(struct pthread *curthread, struct pthread *thread)
188 DBG_MSG("Freeing thread %p\n", thread);
197 _tcb_dtor(thread->tcb);
200 _tcb_dtor(thread->tcb);
202 thread->tcb = NULL;
204 thr_destroy(curthread, thread);
208 * Add the thread to the free thread list, this also avoids
212 TAILQ_INSERT_TAIL(&free_threadq, thread, tle);
219 thr_destroy(struct pthread *curthread __unused, struct pthread *thread)
221 if (thread->sleepqueue != NULL)
222 _sleepq_free(thread->sleepqueue);
223 if (thread->wake_addr != NULL)
224 _thr_release_wake_addr(thread->wake_addr);
225 __thr_free(thread);
229 * Add the thread to the list of all threads and increment
233 _thr_link(struct pthread *curthread, struct pthread *thread)
236 THR_LIST_ADD(thread);
242 * Remove an active thread.
245 _thr_unlink(struct pthread *curthread, struct pthread *thread)
248 THR_LIST_REMOVE(thread);
254 _thr_hash_add(struct pthread *thread)
258 head = &thr_hashtable[THREAD_HASH(thread)];
259 LIST_INSERT_HEAD(head, thread, hle);
263 _thr_hash_remove(struct pthread *thread)
265 LIST_REMOVE(thread, hle);
269 _thr_hash_find(struct pthread *thread)
274 head = &thr_hashtable[THREAD_HASH(thread)];
276 if (td == thread)
277 return (thread);
283 * Find a thread in the linked list of active threads and add a reference
288 _thr_ref_add(struct pthread *curthread, struct pthread *thread,
293 if (thread == NULL)
294 /* Invalid thread: */
297 if ((ret = _thr_find_thread(curthread, thread, include_dead)) == 0) {
298 thread->refcount++;
300 THR_THREAD_UNLOCK(curthread, thread);
303 /* Return zero if the thread exists: */
308 _thr_ref_delete(struct pthread *curthread, struct pthread *thread)
310 THR_THREAD_LOCK(curthread, thread);
311 thread->refcount--;
312 _thr_try_gc(curthread, thread);
316 /* entered with thread lock held, exit with thread lock released */
318 _thr_try_gc(struct pthread *curthread, struct pthread *thread)
320 if (THR_SHOULD_GC(thread)) {
321 THR_REF_ADD(curthread, thread);
322 THR_THREAD_UNLOCK(curthread, thread);
324 THR_THREAD_LOCK(curthread, thread);
325 THR_REF_DEL(curthread, thread);
326 if (THR_SHOULD_GC(thread)) {
327 THR_LIST_REMOVE(thread);
328 THR_GCLIST_ADD(thread);
330 THR_THREAD_UNLOCK(curthread, thread);
333 THR_THREAD_UNLOCK(curthread, thread);
337 /* return with thread lock held if thread is found */
339 _thr_find_thread(struct pthread *curthread, struct pthread *thread,
345 if (thread == NULL)
350 pthread = _thr_hash_find(thread);