r1685 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Fri Jul 13 09:47:45 CEST 2007


Author: phk
Date: 2007-07-13 09:47:45 +0200 (Fri, 13 Jul 2007)
New Revision: 1685

Modified:
   trunk/varnish-cache/bin/varnishd/cache.h
   trunk/varnish-cache/bin/varnishd/cache_center.c
   trunk/varnish-cache/bin/varnishd/cache_pool.c
Log:
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.



Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h	2007-07-13 07:27:50 UTC (rev 1684)
+++ trunk/varnish-cache/bin/varnishd/cache.h	2007-07-13 07:47:45 UTC (rev 1685)
@@ -149,7 +149,7 @@
 	struct objhead		*nobjhead;
 	struct object		*nobj;
 
-	double			idle;
+	double			used;
 
 	int			pipe[2];
 

Modified: trunk/varnish-cache/bin/varnishd/cache_center.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_center.c	2007-07-13 07:27:50 UTC (rev 1684)
+++ trunk/varnish-cache/bin/varnishd/cache_center.c	2007-07-13 07:47:45 UTC (rev 1685)
@@ -185,7 +185,7 @@
 	}
 
 	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 @@
 
 	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 @@
 	/* 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 */

Modified: trunk/varnish-cache/bin/varnishd/cache_pool.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_pool.c	2007-07-13 07:27:50 UTC (rev 1684)
+++ trunk/varnish-cache/bin/varnishd/cache_pool.c	2007-07-13 07:47:45 UTC (rev 1685)
@@ -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 @@
 	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 @@
 		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 @@
 	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 @@
 
 		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 @@
 			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 @@
 			UNLOCK(&qp->mtx);
 			if (w == NULL)
 				continue;
-			w->idle = 0;
+			AZ(w->wrq);
 			assert(1 == write(w->pipe[1], w, 1));
 		}
 	}




More information about the varnish-commit mailing list