From adc2bd5955fdaf7b54668c62d49ad8855449adb0 Mon Sep 17 00:00:00 2001 From: phk Date: Mon, 11 Sep 2006 14:50:56 +0000 Subject: [PATCH] Use a pipe for synchronization instead. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@966 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache.h | 3 +-- varnish-cache/bin/varnishd/cache_pool.c | 14 ++++++-------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index 9b4f5956..e8efeaf6 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -101,8 +101,7 @@ struct worker { time_t idle; - pthread_cond_t cv; - pthread_mutex_t mtx; + int pipe[2]; TAILQ_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 ba90b32e..c9d9f08e 100644 --- a/varnish-cache/bin/varnishd/cache_pool.c +++ b/varnish-cache/bin/varnishd/cache_pool.c @@ -149,14 +149,14 @@ static void * wrk_thread(void *priv) { struct worker *w, ww; + char c; (void)priv; w = &ww; memset(w, 0, sizeof *w); w->magic = WORKER_MAGIC; w->idle = time(NULL); - AZ(pthread_cond_init(&w->cv, NULL)); - AZ(pthread_mutex_init(&w->mtx, NULL)); + AZ(pipe(w->pipe)); VSL(SLT_WorkThread, 0, "%p start", w); LOCK(&wrk_mtx); @@ -170,6 +170,7 @@ wrk_thread(void *priv) if (wrk_overflow > 0) { wrk_overflow--; w->wrq = TAILQ_FIRST(&wrk_reqhead); + AN(w->wrq); TAILQ_REMOVE(&wrk_reqhead, w->wrq, list); VSL_stats->n_wrk_queue--; UNLOCK(&wrk_mtx); @@ -183,9 +184,7 @@ wrk_thread(void *priv) assert(w->idle != 0); VSL_stats->n_wrk_busy--; UNLOCK(&wrk_mtx); - LOCK(&w->mtx); - AZ(pthread_cond_wait(&w->cv, &w->mtx)); - UNLOCK(&w->mtx); + assert(1 == read(w->pipe[0], &c, 1)); if (w->idle == 0) break; wrk_do_one(w); @@ -195,7 +194,6 @@ wrk_thread(void *priv) VSL_stats->n_wrk--; UNLOCK(&wrk_mtx); VSL(SLT_WorkThread, 0, "%p end", w); - AZ(pthread_cond_destroy(&w->cv)); return (NULL); } @@ -219,7 +217,7 @@ WRK_QueueSession(struct sess *sp) VSL_stats->n_wrk_busy++; UNLOCK(&wrk_mtx); w->wrq = &sp->workreq; - AZ(pthread_cond_signal(&w->cv)); + assert(1 == write(w->pipe[1], w, 1)); return; } @@ -277,7 +275,7 @@ wrk_reaperthread(void *priv) if (w == NULL) continue; w->idle = 0; - AZ(pthread_cond_signal(&w->cv)); + assert(1 == write(w->pipe[1], w, 1)); } INCOMPL(); } -- 2.39.5