]> err.no Git - varnish/commitdiff
Rename the "idle" field of struct worker to "used", which is more precise.
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 13 Jul 2007 07:47:45 +0000 (07:47 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 13 Jul 2007 07:47:45 +0000 (07:47 +0000)
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
varnish-cache/bin/varnishd/cache_center.c
varnish-cache/bin/varnishd/cache_pool.c

index e430213064af1bc8126aff427ef8440ca953e344..c8d9506d85dd3a3e15e8dff64d29420204557d67 100644 (file)
@@ -149,7 +149,7 @@ struct worker {
        struct objhead          *nobjhead;
        struct object           *nobj;
 
-       double                  idle;
+       double                  used;
 
        int                     pipe[2];
 
index 4a7fec888f7a37ba5b1eaeae610b49b916fcffc5..23f29815684f2611b0874ad9a2711612060f686e 100644 (file)
@@ -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 */
index e04055797925e71a64686c74da96a6481ec66ce8..9350adfc420dbbac3d39a06bfcc14f63ec85d8ef 100644 (file)
@@ -46,6 +46,7 @@
 
 #include <errno.h>
 #include <stdio.h>
+#include <math.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
@@ -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));
                }
        }