]> err.no Git - varnish/commitdiff
Use a private cond-var for each worker thread, instead of pipe(2)-pair, it is cheaper.
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Thu, 13 Mar 2008 12:49:36 +0000 (12:49 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Thu, 13 Mar 2008 12:49:36 +0000 (12:49 +0000)
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2605 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/cache.h
varnish-cache/bin/varnishd/cache_pool.c

index e56474e4cee64701937544c470a061d9162bb9a2..3b27d78dd78a01264baf15ee5d9c4caab92cf7f6 100644 (file)
@@ -174,7 +174,7 @@ struct worker {
 
        double                  used;
 
-       int                     pipe[2];
+       pthread_cond_t          cond;
 
        VTAILQ_ENTRY(worker)    list;
        struct workreq          *wrq;
index 8ad13e65ba99b2adcf614504961166da97473462..4ea04c06c955bf38c7d15ccd0ea206a52e2b79da 100644 (file)
@@ -203,7 +203,6 @@ wrk_thread(void *priv)
 {
        struct worker *w, ww;
        struct wq *qp;
-       char c;
        unsigned char wlog[8192];       /* XXX: size */
 
        THR_Name("cache-worker");
@@ -214,7 +213,7 @@ wrk_thread(void *priv)
        w->used = TIM_real();
        w->wlb = w->wlp = wlog;
        w->wle = wlog + sizeof wlog;
-       AZ(pipe(w->pipe));
+       AZ(pthread_cond_init(&w->cond, NULL));
 
        VSL(SLT_WorkThread, 0, "%p start", w);
        LOCK(&tmtx);
@@ -240,8 +239,8 @@ wrk_thread(void *priv)
                if (w->wrq == NULL) {
                        LOCK(&qp->mtx);
                        VTAILQ_INSERT_HEAD(&qp->idle, w, list);
+                       AZ(pthread_cond_wait(&w->cond, &qp->mtx));
                        UNLOCK(&qp->mtx);
-                       assert(1 == read(w->pipe[0], &c, 1));
                }
                if (w->wrq == NULL)
                        break;
@@ -256,8 +255,7 @@ wrk_thread(void *priv)
        VSL(SLT_WorkThread, 0, "%p end", w);
        if (w->vcl != NULL)
                VCL_Rel(&w->vcl);
-       AZ(close(w->pipe[0]));
-       AZ(close(w->pipe[1]));
+       AZ(pthread_cond_destroy(&w->cond));
        if (w->srcaddr != NULL)
                free(w->srcaddr);
        if (w->nobjhead != NULL) {
@@ -295,7 +293,7 @@ WRK_QueueSession(struct sess *sp)
                VTAILQ_REMOVE(&qp->idle, w, list);
                UNLOCK(&qp->mtx);
                w->wrq = &sp->workreq;
-               assert(1 == write(w->pipe[1], w, 1));
+               AZ(pthread_cond_signal(&w->cond));
                return;
        }
 
@@ -423,7 +421,7 @@ wrk_reaperthread(void *priv)
                        if (w == NULL)
                                continue;
                        AZ(w->wrq);
-                       assert(1 == write(w->pipe[1], w, 1));
+                       AZ(pthread_cond_signal(&w->cond));
                }
        }
 }