PERFORCE change 67975 for review

David Xu davidxu at FreeBSD.org
Fri Dec 31 06:55:02 PST 2004


http://perforce.freebsd.org/chv.cgi?CH=67975

Change 67975 by davidxu at 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);
 }


More information about the p4-projects mailing list