Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 16 Jan 2004 11:10:28 -0800 (PST)
From:      John Baldwin <jhb@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 45452 for review
Message-ID:  <200401161910.i0GJAS9E012411@repoman.freebsd.org>

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

Change 45452 by jhb@jhb_slimer on 2004/01/16 11:09:55

	Use a cv rather than a semaphore.  Less lock operations that way.

Affected files ...

.. //depot/projects/smpng/sys/kern/kern_ktrace.c#36 edit

Differences ...

==== //depot/projects/smpng/sys/kern/kern_ktrace.c#36 (text+ko) ====

@@ -54,7 +54,6 @@
 #include <sys/unistd.h>
 #include <sys/vnode.h>
 #include <sys/ktrace.h>
-#include <sys/sema.h>
 #include <sys/sx.h>
 #include <sys/sysctl.h>
 #include <sys/syslog.h>
@@ -108,7 +107,7 @@
 
 static int print_message = 1;
 struct mtx ktrace_mtx;
-static struct sema ktrace_sema;
+static struct cv ktrace_cv;
 
 static void ktrace_init(void *dummy);
 static int sysctl_kern_ktrace_request_pool(SYSCTL_HANDLER_ARGS);
@@ -129,7 +128,7 @@
 	int i;
 
 	mtx_init(&ktrace_mtx, "ktrace", NULL, MTX_DEF | MTX_QUIET);
-	sema_init(&ktrace_sema, 0, "ktrace");
+	cv_init(&ktrace_cv, "ktrace");
 	STAILQ_INIT(&ktr_todo);
 	STAILQ_INIT(&ktr_free);
 	for (i = 0; i < ktr_requestpool; i++) {
@@ -263,8 +262,8 @@
 
 	mtx_lock(&ktrace_mtx);
 	STAILQ_INSERT_TAIL(&ktr_todo, req, ktr_list);
+	cv_signal(&ktrace_cv);
 	mtx_unlock(&ktrace_mtx);
-	sema_post(&ktrace_sema);
 	curthread->td_pflags &= ~TDP_INKTRACE;
 }
 
@@ -296,8 +295,9 @@
 	td = curthread;
 	cred = td->td_ucred;
 	for (;;) {
-		sema_wait(&ktrace_sema);
 		mtx_lock(&ktrace_mtx);
+		while (STAILQ_EMPTY(&ktr_todo))
+			cv_wait(&ktrace_cv, &ktrace_mtx);
 		req = STAILQ_FIRST(&ktr_todo);
 		STAILQ_REMOVE_HEAD(&ktr_todo, ktr_list);
 		KASSERT(req != NULL, ("got a NULL request"));



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