r2605 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Thu Mar 13 13:49:37 CET 2008


Author: phk
Date: 2008-03-13 13:49:36 +0100 (Thu, 13 Mar 2008)
New Revision: 2605

Modified:
   trunk/varnish-cache/bin/varnishd/cache.h
   trunk/varnish-cache/bin/varnishd/cache_pool.c
Log:
Use a private cond-var for each worker thread, instead of pipe(2)-pair, it is cheaper.


Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h	2008-03-13 10:34:30 UTC (rev 2604)
+++ trunk/varnish-cache/bin/varnishd/cache.h	2008-03-13 12:49:36 UTC (rev 2605)
@@ -174,7 +174,7 @@
 
 	double			used;
 
-	int			pipe[2];
+	pthread_cond_t		cond;
 
 	VTAILQ_ENTRY(worker)	list;
 	struct workreq		*wrq;

Modified: trunk/varnish-cache/bin/varnishd/cache_pool.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_pool.c	2008-03-13 10:34:30 UTC (rev 2604)
+++ trunk/varnish-cache/bin/varnishd/cache_pool.c	2008-03-13 12:49:36 UTC (rev 2605)
@@ -203,7 +203,6 @@
 {
 	struct worker *w, ww;
 	struct wq *qp;
-	char c;
 	unsigned char wlog[8192]; 	/* XXX: size */
 
 	THR_Name("cache-worker");
@@ -214,7 +213,7 @@
 	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 @@
 		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 @@
 	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 @@
 		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 @@
 			if (w == NULL)
 				continue;
 			AZ(w->wrq);
-			assert(1 == write(w->pipe[1], w, 1));
+			AZ(pthread_cond_signal(&w->cond));
 		}
 	}
 }




More information about the varnish-commit mailing list