Date: Fri, 31 Dec 2004 14:55:01 GMT From: David Xu <davidxu@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 67975 for review Message-ID: <200412311455.iBVEt1pX009089@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=67975 Change 67975 by davidxu@davidxu_tiger on 2004/12/31 14:54:05 add _thr_find_thread(). Affected files ... .. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_find_thread.c#3 edit Differences ... ==== //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_find_thread.c#3 (text+ko) ==== @@ -45,43 +45,55 @@ _thr_ref_add(struct pthread *curthread, struct pthread *thread, int include_dead) { - struct pthread *pthread; + int ret; if (thread == NULL) /* Invalid thread: */ return (EINVAL); - THR_LOCK_ACQUIRE(curthread, &_thread_list_lock); - pthread = _thr_hash_find(thread); - if (pthread) { - if ((include_dead == 0) && - ((pthread->state == PS_DEAD) || - ((pthread->state == PS_DEADLOCK) || - ((pthread->flags & THR_FLAGS_EXITING) != 0)))) - pthread = NULL; - else { - pthread->refcount++; - if (curthread != NULL) - curthread->critical_count++; - } + THREAD_LIST_LOCK(curthread); + if ((ret = _thr_find_thread(curthread, thread, include_dead)) == 0) { + thread->refcount++; + if (curthread != NULL) + curthread->critical_count++; } - THR_LOCK_RELEASE(curthread, &_thread_list_lock); + THREAD_LIST_UNLOCK(curthread); /* Return zero if the thread exists: */ - return ((pthread != NULL) ? 0 : ESRCH); + return (ret); } void _thr_ref_delete(struct pthread *curthread, struct pthread *thread) { if (thread != NULL) { - THR_LOCK_ACQUIRE(curthread, &_thread_list_lock); + THREAD_LIST_LOCK(curthread); thread->refcount--; if (curthread != NULL) curthread->critical_count--; if ((thread->refcount == 0) && (thread->tlflags & TLFLAGS_GC_SAFE) != 0) THR_GCLIST_ADD(thread); - THR_LOCK_RELEASE(curthread, &_thread_list_lock); + THREAD_LIST_UNLOCK(curthread); + } +} + +int +_thr_find_thread(struct pthread *curthread, struct pthread *thread, + int include_dead) +{ + struct pthread *pthread; + + if (thread == NULL) + /* Invalid thread: */ + return (EINVAL); + + pthread = _thr_hash_find(thread); + if (pthread) { + if (include_dead == 0 && pthread->state == PS_DEAD) + pthread = NULL; } + + /* Return zero if the thread exists: */ + return ((pthread != NULL) ? 0 : ESRCH); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200412311455.iBVEt1pX009089>