From fe19b886a785b2ef425b3d81781075848a964e96 Mon Sep 17 00:00:00 2001 From: phk Date: Fri, 13 Jul 2007 07:47:45 +0000 Subject: [PATCH] Rename the "idle" field of struct worker to "used", which is more precise. Don't use the "used" field to signal suicide for worker threads, use the "wrq" field which is much more natural. Set the "used" field to NAN before doing anything and assert that somebody updated during the task. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1685 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache.h | 2 +- varnish-cache/bin/varnishd/cache_center.c | 6 +++--- varnish-cache/bin/varnishd/cache_pool.c | 13 ++++++++----- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index e4302130..c8d9506d 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -149,7 +149,7 @@ struct worker { struct objhead *nobjhead; struct object *nobj; - double idle; + double used; int pipe[2]; diff --git a/varnish-cache/bin/varnishd/cache_center.c b/varnish-cache/bin/varnishd/cache_center.c index 4a7fec88..23f29815 100644 --- a/varnish-cache/bin/varnishd/cache_center.c +++ b/varnish-cache/bin/varnishd/cache_center.c @@ -185,7 +185,7 @@ cnt_done(struct sess *sp) } sp->t_end = TIM_real(); - sp->wrk->idle = sp->t_end; + sp->wrk->used = sp->t_end; if (sp->xid == 0) { sp->t_req = sp->t_end; sp->t_resp = sp->t_end; @@ -332,7 +332,7 @@ cnt_first(struct sess *sp) assert(sp->xid == 0); VCA_Prep(sp); - sp->wrk->idle = sp->t_open; + sp->wrk->used = sp->t_open; sp->wrk->acct.sess++; SES_RefSrcAddr(sp); do @@ -660,7 +660,7 @@ cnt_recv(struct sess *sp) /* Update stats of various sorts */ VSL_stats->client_req++; /* XXX not locked */ sp->t_req = TIM_real(); - sp->wrk->idle = sp->t_req; + sp->wrk->used = sp->t_req; sp->wrk->acct.req++; /* Assign XID and log */ diff --git a/varnish-cache/bin/varnishd/cache_pool.c b/varnish-cache/bin/varnishd/cache_pool.c index e0405579..9350adfc 100644 --- a/varnish-cache/bin/varnishd/cache_pool.c +++ b/varnish-cache/bin/varnishd/cache_pool.c @@ -46,6 +46,7 @@ #include #include +#include #include #include #include @@ -181,6 +182,7 @@ wrk_do_one(struct worker *w) struct workreq *wrq; AN(w->wrq); + w->used = NAN; wrq = w->wrq; CHECK_OBJ_NOTNULL(wrq->sess, SESS_MAGIC); wrq->sess->wrk = w; @@ -193,6 +195,7 @@ wrk_do_one(struct worker *w) CHECK_OBJ(w->nobj, OBJECT_MAGIC); if (w->nobjhead != NULL) CHECK_OBJ(w->nobjhead, OBJHEAD_MAGIC); + assert(!isnan(w->used)); w->wrq = NULL; } @@ -207,7 +210,7 @@ wrk_thread(void *priv) w = &ww; memset(w, 0, sizeof *w); w->magic = WORKER_MAGIC; - w->idle = TIM_real(); + w->used = TIM_real(); w->wlp = w->wlog; w->wle = w->wlog + sizeof w->wlog; AZ(pipe(w->pipe)); @@ -236,10 +239,10 @@ wrk_thread(void *priv) LOCK(&qp->mtx); TAILQ_INSERT_HEAD(&qp->idle, w, list); - assert(w->idle != 0); + assert(!isnan(w->used)); UNLOCK(&qp->mtx); assert(1 == read(w->pipe[0], &c, 1)); - if (w->idle == 0) + if (w->wrq == NULL) break; wrk_do_one(w); } @@ -398,7 +401,7 @@ wrk_reaperthread(void *priv) LOCK(&qp->mtx); w = TAILQ_LAST(&qp->idle, workerhead); if (w != NULL && - (w->idle + params->wthread_timeout < now || + (w->used + params->wthread_timeout < now || VSL_stats->n_wrk > params->wthread_max)) TAILQ_REMOVE(&qp->idle, w, list); else @@ -406,7 +409,7 @@ wrk_reaperthread(void *priv) UNLOCK(&qp->mtx); if (w == NULL) continue; - w->idle = 0; + AZ(w->wrq); assert(1 == write(w->pipe[1], w, 1)); } } -- 2.39.5