Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/librumpuser Turn the "idle workers available" from a fla...



details:   https://anonhg.NetBSD.org/src/rev/c96f9f02bf57
branches:  trunk
changeset: 761819:c96f9f02bf57
user:      pooka <pooka%NetBSD.org@localhost>
date:      Tue Feb 08 11:21:22 2011 +0000

description:
Turn the "idle workers available" from a flag into a counter so
that we can finally avoid all races (*knock knock*).

diffstat:

 lib/librumpuser/rumpuser_sp.c |  19 +++++++++++--------
 1 files changed, 11 insertions(+), 8 deletions(-)

diffs (60 lines):

diff -r 6e7732973cb2 -r c96f9f02bf57 lib/librumpuser/rumpuser_sp.c
--- a/lib/librumpuser/rumpuser_sp.c     Tue Feb 08 11:09:14 2011 +0000
+++ b/lib/librumpuser/rumpuser_sp.c     Tue Feb 08 11:21:22 2011 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: rumpuser_sp.c,v 1.39 2011/02/06 18:25:48 pooka Exp $  */
+/*      $NetBSD: rumpuser_sp.c,v 1.40 2011/02/08 11:21:22 pooka Exp $  */
 
 /*
  * Copyright (c) 2010, 2011 Antti Kantee.  All Rights Reserved.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: rumpuser_sp.c,v 1.39 2011/02/06 18:25:48 pooka Exp $");
+__RCSID("$NetBSD: rumpuser_sp.c,v 1.40 2011/02/08 11:21:22 pooka Exp $");
 
 #include <sys/types.h>
 #include <sys/atomic.h>
@@ -604,7 +604,7 @@
 };
 static pthread_mutex_t sbamtx;
 static pthread_cond_t sbacv;
-static int nworker, idleworker;
+static int nworker, idleworker, nwork;
 static TAILQ_HEAD(, sysbouncearg) syslist = TAILQ_HEAD_INITIALIZER(syslist);
 
 /*ARGSUSED*/
@@ -620,13 +620,16 @@
                        pthread_mutex_unlock(&sbamtx);
                        break;
                }
-               if (TAILQ_EMPTY(&syslist))
-                       idleworker++;
-               while (TAILQ_EMPTY(&syslist))
+               idleworker++;
+               while (TAILQ_EMPTY(&syslist)) {
+                       _DIAGASSERT(nwork == 0);
                        pthread_cond_wait(&sbacv, &sbamtx);
+               }
+               idleworker--;
 
                sba = TAILQ_FIRST(&syslist);
                TAILQ_REMOVE(&syslist, sba, sba_entries);
+               nwork--;
                pthread_mutex_unlock(&sbamtx);
 
                serv_handlesyscall(sba->sba_spc,
@@ -948,10 +951,10 @@
 
        pthread_mutex_lock(&sbamtx);
        TAILQ_INSERT_TAIL(&syslist, sba, sba_entries);
-       if (idleworker > 0) {
+       nwork++;
+       if (nwork <= idleworker) {
                /* do we have a daemon's tool (i.e. idle threads)? */
                pthread_cond_signal(&sbacv);
-               idleworker--;
        } else if (nworker < rumpsp_maxworker) {
                /*
                 * Else, need to create one



Home | Main Index | Thread Index | Old Index