PERFORCE change 45452 for review
John Baldwin
jhb at FreeBSD.org
Fri Jan 16 11:10:31 PST 2004
http://perforce.freebsd.org/chv.cgi?CH=45452
Change 45452 by jhb at 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"));
More information about the p4-projects
mailing list