diff options
author | davidxu <davidxu@FreeBSD.org> | 2006-01-05 13:51:22 +0000 |
---|---|---|
committer | davidxu <davidxu@FreeBSD.org> | 2006-01-05 13:51:22 +0000 |
commit | d6c88c0f27b6e6c0006896e7fb3e47f0f7e992d8 (patch) | |
tree | 7cdbbed3366ccd9eec189ba14d2d48ff355912e4 /lib/libthr/thread/thr_list.c | |
parent | e065d5a1853d5ac2323fc116b1b2462841c0160e (diff) | |
download | FreeBSD-src-d6c88c0f27b6e6c0006896e7fb3e47f0f7e992d8.zip FreeBSD-src-d6c88c0f27b6e6c0006896e7fb3e47f0f7e992d8.tar.gz |
Refine thread suspension code, now thread suspension is a blockable
operation, the caller is blocked util target threads are really
suspended, also avoid suspending a thread when it is holding a
critical lock.
Fix a bug in _thr_ref_delete which tests a never set flag.
Diffstat (limited to 'lib/libthr/thread/thr_list.c')
-rw-r--r-- | lib/libthr/thread/thr_list.c | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/lib/libthr/thread/thr_list.c b/lib/libthr/thread/thr_list.c index a0d5aaa..ede90ce 100644 --- a/lib/libthr/thread/thr_list.c +++ b/lib/libthr/thread/thr_list.c @@ -129,7 +129,6 @@ _thr_gc(struct pthread *curthread) continue; } - DBG_MSG("Freeing thread %p\n", td); _thr_free(curthread, td); } } @@ -224,8 +223,6 @@ _thr_link(struct pthread *curthread, struct pthread *thread) { THREAD_LIST_LOCK(curthread); THR_LIST_ADD(thread); - if (thread->attr.flags & PTHREAD_DETACHED) - thread->tlflags |= TLFLAGS_DETACHED; _thread_active_threads++; THREAD_LIST_UNLOCK(curthread); } @@ -299,13 +296,19 @@ _thr_ref_add(struct pthread *curthread, struct pthread *thread, void _thr_ref_delete(struct pthread *curthread, struct pthread *thread) { + THREAD_LIST_LOCK(curthread); + _thr_ref_delete_unlocked(curthread, thread); + THREAD_LIST_UNLOCK(curthread); +} + +void +_thr_ref_delete_unlocked(struct pthread *curthread, struct pthread *thread) +{ if (thread != NULL) { - THREAD_LIST_LOCK(curthread); thread->refcount--; - if ((thread->refcount == 0) && - (thread->tlflags & TLFLAGS_GC_SAFE) != 0) + if ((thread->refcount == 0) && thread->state == PS_DEAD && + (thread->tlflags & TLFLAGS_DETACHED) != 0) THR_GCLIST_ADD(thread); - THREAD_LIST_UNLOCK(curthread); } } |