r1731 - trunk/varnish-cache/bin/varnishd

cecilihf at projects.linpro.no cecilihf at projects.linpro.no
Fri Jul 20 11:19:36 CEST 2007


Author: cecilihf
Date: 2007-07-20 11:19:36 +0200 (Fri, 20 Jul 2007)
New Revision: 1731

Modified:
   trunk/varnish-cache/bin/varnishd/heritage.h
   trunk/varnish-cache/bin/varnishd/stevedore.c
Log:
Added locking on the list manipulation.


Modified: trunk/varnish-cache/bin/varnishd/heritage.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/heritage.h	2007-07-20 09:06:42 UTC (rev 1730)
+++ trunk/varnish-cache/bin/varnishd/heritage.h	2007-07-20 09:19:36 UTC (rev 1731)
@@ -31,6 +31,7 @@
  * This file contains the heritage passed when mgt forks cache
  */
 
+#include <pthread.h>
 #include "queue.h"
 
 struct listen_sock {
@@ -60,6 +61,7 @@
 
 	/* Storage method */
 	struct stevedore_head		stevedore_h;
+	pthread_mutex_t stevedore_lock;
 
 	/* Hash method */
 	struct hash_slinger		*hash;

Modified: trunk/varnish-cache/bin/varnishd/stevedore.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/stevedore.c	2007-07-20 09:06:42 UTC (rev 1730)
+++ trunk/varnish-cache/bin/varnishd/stevedore.c	2007-07-20 09:19:36 UTC (rev 1731)
@@ -46,8 +46,8 @@
 	struct stevedore *stv, *stv_first;
 	struct stevedore_head *stevedore_h = &heritage.stevedore_h;
 
-	/* Simple round robin selecting of a stevedore.
-	 */
+	/* Simple round robin selecting of a stevedore. */
+	pthread_mutex_lock(&heritage.stevedore_lock);
 	stv_first = TAILQ_FIRST(stevedore_h);
 	stv = stv_first;
 	do {
@@ -55,8 +55,10 @@
 		st = stv->alloc(stv, size);
 		TAILQ_REMOVE(stevedore_h, stv, stevedore_list);
 		TAILQ_INSERT_TAIL(stevedore_h, stv, stevedore_list);
-		if (st != NULL)
+		if (st != NULL) {
+			pthread_mutex_unlock(&heritage.stevedore_lock);
 			return (st);
+		}
 	} while ((stv = TAILQ_FIRST(stevedore_h)) != stv_first);
 	
 	/* No stevedore with enough space is found. Make room in the first
@@ -65,6 +67,7 @@
 	stv = TAILQ_FIRST(stevedore_h);
 	TAILQ_REMOVE(stevedore_h, stv, stevedore_list);
 	TAILQ_INSERT_TAIL(stevedore_h, stv, stevedore_list);
+	pthread_mutex_unlock(&heritage.stevedore_lock);
 	
 	do {
 		if ((st = stv->alloc(stv, size)) == NULL)
@@ -143,4 +146,5 @@
 		if (st->open != NULL)
 			st->open(st);
 	}
+	pthread_mutex_init(&heritage.stevedore_lock, NULL);
 }




More information about the varnish-commit mailing list