From 7610ad3abf5b74c4edb158bd442fb81569f597e7 Mon Sep 17 00:00:00 2001 From: cecilihf Date: Fri, 20 Jul 2007 09:19:36 +0000 Subject: [PATCH] Added locking on the list manipulation. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1731 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/heritage.h | 2 ++ varnish-cache/bin/varnishd/stevedore.c | 10 +++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/varnish-cache/bin/varnishd/heritage.h b/varnish-cache/bin/varnishd/heritage.h index d70e3589..249224a4 100644 --- a/varnish-cache/bin/varnishd/heritage.h +++ b/varnish-cache/bin/varnishd/heritage.h @@ -31,6 +31,7 @@ * This file contains the heritage passed when mgt forks cache */ +#include #include "queue.h" struct listen_sock { @@ -60,6 +61,7 @@ struct heritage { /* Storage method */ struct stevedore_head stevedore_h; + pthread_mutex_t stevedore_lock; /* Hash method */ struct hash_slinger *hash; diff --git a/varnish-cache/bin/varnishd/stevedore.c b/varnish-cache/bin/varnishd/stevedore.c index 79878764..9e597b38 100644 --- a/varnish-cache/bin/varnishd/stevedore.c +++ b/varnish-cache/bin/varnishd/stevedore.c @@ -46,8 +46,8 @@ STV_alloc(size_t size) 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 @@ STV_alloc(size_t size) 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_alloc(size_t size) 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 @@ STV_open(void) if (st->open != NULL) st->open(st); } + pthread_mutex_init(&heritage.stevedore_lock, NULL); } -- 2.39.5