r263 - trunk/varnish-cache/bin/varnishd
phk at projects.linpro.no
phk at projects.linpro.no
Wed Jun 28 23:33:06 CEST 2006
Author: phk
Date: 2006-06-28 23:33:06 +0200 (Wed, 28 Jun 2006)
New Revision: 263
Modified:
trunk/varnish-cache/bin/varnishd/cache_shmlog.c
Log:
Put a mutex around the shmlog writes, I've seen my first race.
Modified: trunk/varnish-cache/bin/varnishd/cache_shmlog.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_shmlog.c 2006-06-28 21:18:00 UTC (rev 262)
+++ trunk/varnish-cache/bin/varnishd/cache_shmlog.c 2006-06-28 21:33:06 UTC (rev 263)
@@ -11,6 +11,7 @@
#include <string.h>
#include <stdarg.h>
#include <sys/mman.h>
+#include <pthread.h>
#include "libvarnish.h"
#include "shmlog.h"
@@ -21,6 +22,7 @@
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 @@
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 @@
loghead->ptr = (p + 4 + (e - b)) - logstart;
- /* XXX: Unlock */
+ AZ(pthread_mutex_unlock(&vsl_mutex));
}
@@ -76,7 +78,7 @@
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 @@
loghead->ptr = (p + 4 + n) - logstart;
- /* XXX: Unlock */
+ AZ(pthread_mutex_unlock(&vsl_mutex));
va_end(ap);
}
@@ -138,6 +140,7 @@
logstart = (unsigned char *)loghead + loghead->start;
logend = logstart + loghead->size;
VSL_stats = &loghead->stats;
+ AZ(pthread_mutex_init(&vsl_mutex, NULL));
}
/*--------------------------------------------------------------------*/
More information about the varnish-commit
mailing list