Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 11 Mar 2003 09:32:12 -0800 (PST)
From:      John Baldwin <jhb@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 26689 for review
Message-ID:  <200303111732.h2BHWC2q060221@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=26689

Change 26689 by jhb@jhb_laptop on 2003/03/11 09:31:59

	Keep a count of alive threads and use that instead of the for loop
	to set the broadcast count in thread_destroy().  Also, don't wait
	on event_rcvd if num_threads is 0.

Affected files ...

.. //depot/projects/smpng/sys/modules/evtest/evtest.c#13 edit

Differences ...

==== //depot/projects/smpng/sys/modules/evtest/evtest.c#13 (text+ko) ====

@@ -61,7 +61,7 @@
 static struct cv event_cv, broadcast_cv, event_recvd;
 static struct mtx event_mtx;
 static struct sema evtest_sema;
-static int event, broadcast_count;
+static int event, broadcast_count, num_threads;
 
 struct thread_info {
 	struct proc *ti_p;
@@ -332,28 +332,28 @@
 	TD_SET_CAN_RUN(td);
 	setrunqueue(td);
 	mtx_unlock_spin(&sched_lock);
+	mtx_lock(&event_mtx);
+	num_threads++;
+	mtx_unlock(&event_mtx);
 	return (0);
 }
 
 static void
 thread_destroy(int i)
 {
-	int j;
 
 	if (i < 0 || i >= NUM_THREADS || threads[i].ti_p == NULL)
 		return;
 	mtx_assert(&event_mtx, MA_OWNED);
 	printf("%s: killing thread %d\n", __func__, i);
 	threads[i].ti_event = -1;
-	broadcast_count = 0;
-	for (j = 0; j < NUM_THREADS; j++)
-		if (threads[j].ti_p != NULL)
-			broadcast_count++;
+	broadcast_count = num_threads;
 	event = -1;
 	cv_broadcast(&event_cv);
 	msleep(threads[i].ti_p, &event_mtx, PWAIT, "evtstun", 0);
 	threads[i].ti_p = NULL;
-	if (event != 0)
+	num_threads--;
+	if (event != 0 && num_threads > 0)
 		cv_wait(&event_recvd, &event_mtx);
 }
 
@@ -388,6 +388,7 @@
 
 	event = 0;
 	broadcast_count = 0;
+	num_threads = 0;
 	mtx_init(&event_mtx, "evtest event", NULL, MTX_DEF);
 	cv_init(&event_cv, "evtest");
 	cv_init(&event_recvd, "evrcvd");

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe p4-projects" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200303111732.h2BHWC2q060221>