diff options
author | davidxu <davidxu@FreeBSD.org> | 2010-09-13 07:03:01 +0000 |
---|---|---|
committer | davidxu <davidxu@FreeBSD.org> | 2010-09-13 07:03:01 +0000 |
commit | e87e922f3125332f002638f5f231acc7544b7ebf (patch) | |
tree | 82f35174d92e7167b6c95a574f45720b60ded582 /lib/libthr/thread/thr_join.c | |
parent | 8ff2afea3997418eb503ad0843ed126e994fe54b (diff) | |
download | FreeBSD-src-e87e922f3125332f002638f5f231acc7544b7ebf.zip FreeBSD-src-e87e922f3125332f002638f5f231acc7544b7ebf.tar.gz |
Convert thread list lock from mutex to rwlock.
Diffstat (limited to 'lib/libthr/thread/thr_join.c')
-rw-r--r-- | lib/libthr/thread/thr_join.c | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/lib/libthr/thread/thr_join.c b/lib/libthr/thread/thr_join.c index d3c8367..4f26862 100644 --- a/lib/libthr/thread/thr_join.c +++ b/lib/libthr/thread/thr_join.c @@ -43,12 +43,12 @@ __weak_reference(_pthread_timedjoin_np, pthread_timedjoin_np); static void backout_join(void *arg) { - struct pthread *curthread = _get_curthread(); struct pthread *pthread = (struct pthread *)arg; + struct pthread *curthread = _get_curthread(); - THREAD_LIST_LOCK(curthread); + THR_THREAD_LOCK(curthread, pthread); pthread->joiner = NULL; - THREAD_LIST_UNLOCK(curthread); + THR_THREAD_LOCK(curthread, pthread); } int @@ -88,23 +88,23 @@ join_common(pthread_t pthread, void **thread_return, if (pthread == curthread) return (EDEADLK); - THREAD_LIST_LOCK(curthread); - if ((ret = _thr_find_thread(curthread, pthread, 1)) != 0) { - ret = ESRCH; - } else if ((pthread->tlflags & TLFLAGS_DETACHED) != 0) { + if ((ret = _thr_find_thread(curthread, pthread, 1)) != 0) + return (ESRCH); + + if ((pthread->flags & THR_FLAGS_DETACHED) != 0) { ret = EINVAL; } else if (pthread->joiner != NULL) { /* Multiple joiners are not supported. */ ret = ENOTSUP; } if (ret) { - THREAD_LIST_UNLOCK(curthread); + THR_THREAD_UNLOCK(curthread, pthread); return (ret); } /* Set the running thread to be the joiner: */ pthread->joiner = curthread; - THREAD_LIST_UNLOCK(curthread); + THR_THREAD_UNLOCK(curthread, pthread); THR_CLEANUP_PUSH(curthread, backout_join, pthread); _thr_cancel_enter(curthread); @@ -131,17 +131,16 @@ join_common(pthread_t pthread, void **thread_return, THR_CLEANUP_POP(curthread, 0); if (ret == ETIMEDOUT) { - THREAD_LIST_LOCK(curthread); + THR_THREAD_LOCK(curthread, pthread); pthread->joiner = NULL; - THREAD_LIST_UNLOCK(curthread); + THR_THREAD_UNLOCK(curthread, pthread); } else { ret = 0; tmp = pthread->ret; - THREAD_LIST_LOCK(curthread); - pthread->tlflags |= TLFLAGS_DETACHED; + THR_THREAD_LOCK(curthread, pthread); + pthread->flags |= THR_FLAGS_DETACHED; pthread->joiner = NULL; - THR_GCLIST_ADD(pthread); - THREAD_LIST_UNLOCK(curthread); + _thr_try_gc(curthread, pthread); /* thread lock released */ if (thread_return != NULL) *thread_return = tmp; |