From: phk Date: Thu, 13 Mar 2008 12:49:36 +0000 (+0000) Subject: Use a private cond-var for each worker thread, instead of pipe(2)-pair, it is cheaper. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d9518b469b1e6b49712a878e1865659da47e4d7d;p=varnish Use a private cond-var for each worker thread, instead of pipe(2)-pair, it is cheaper. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2605 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index e56474e4..3b27d78d 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -174,7 +174,7 @@ struct worker { double used; - int pipe[2]; + pthread_cond_t cond; VTAILQ_ENTRY(worker) list; struct workreq *wrq; diff --git a/varnish-cache/bin/varnishd/cache_pool.c b/varnish-cache/bin/varnishd/cache_pool.c index 8ad13e65..4ea04c06 100644 --- a/varnish-cache/bin/varnishd/cache_pool.c +++ b/varnish-cache/bin/varnishd/cache_pool.c @@ -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)); } } }