From: phk Date: Wed, 28 Jun 2006 21:33:06 +0000 (+0000) Subject: Put a mutex around the shmlog writes, I've seen my first race. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8f39cbc3c6e94b20a1dd8c9a3b05937e09cc6651;p=varnish Put a mutex around the shmlog writes, I've seen my first race. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@263 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/cache_shmlog.c b/varnish-cache/bin/varnishd/cache_shmlog.c index de42fadf..be4e27f0 100644 --- a/varnish-cache/bin/varnishd/cache_shmlog.c +++ b/varnish-cache/bin/varnishd/cache_shmlog.c @@ -11,6 +11,7 @@ #include #include #include +#include #include "libvarnish.h" #include "shmlog.h" @@ -21,6 +22,7 @@ struct varnish_stats *VSL_stats; static struct shmloghead *loghead; static unsigned char *logstart, *logend; +static pthread_mutex_t vsl_mutex; /* * This variant copies a byte-range directly to the log, without @@ -41,7 +43,7 @@ VSLR(enum shmlogtag tag, unsigned id, const char *b, const char *e) if (e - b > 255) e = b + 255; - /* XXX: Lock */ + AZ(pthread_mutex_lock(&vsl_mutex)); q = NULL; p = logstart + loghead->ptr; assert(p < logend); @@ -63,7 +65,7 @@ VSLR(enum shmlogtag tag, unsigned id, const char *b, const char *e) loghead->ptr = (p + 4 + (e - b)) - logstart; - /* XXX: Unlock */ + AZ(pthread_mutex_unlock(&vsl_mutex)); } @@ -76,7 +78,7 @@ VSL(enum shmlogtag tag, unsigned id, const char *fmt, ...) va_start(ap, fmt); - /* XXX: Lock */ + AZ(pthread_mutex_lock(&vsl_mutex)); q = NULL; p = logstart + loghead->ptr; assert(p < logend); @@ -119,7 +121,7 @@ VSL(enum shmlogtag tag, unsigned id, const char *fmt, ...) loghead->ptr = (p + 4 + n) - logstart; - /* XXX: Unlock */ + AZ(pthread_mutex_unlock(&vsl_mutex)); va_end(ap); } @@ -138,6 +140,7 @@ VSL_Init(void) logstart = (unsigned char *)loghead + loghead->start; logend = logstart + loghead->size; VSL_stats = &loghead->stats; + AZ(pthread_mutex_init(&vsl_mutex, NULL)); } /*--------------------------------------------------------------------*/