[master] 3025017 Add locks to busyobj's and use locks on refcounting.
Martin Blix Grydeland
martin at varnish-cache.org
Tue Dec 6 14:08:08 CET 2011
commit 3025017171ad9d0959dfee5b5760b044cd4501e7
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date: Tue Dec 6 11:55:58 2011 +0100
Add locks to busyobj's and use locks on refcounting.
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 347de56..cf0a6ee 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -496,6 +496,8 @@ oc_getlru(const struct objcore *oc)
struct busyobj {
unsigned magic;
#define BUSYOBJ_MAGIC 0x23b95567
+ struct lock mtx;
+ /* Members passed this line are cleared on reuse */
unsigned refcount;
uint8_t *vary;
diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c
index 263aa17..ef937ea 100644
--- a/bin/varnishd/cache/cache_backend.c
+++ b/bin/varnishd/cache/cache_backend.c
@@ -34,6 +34,8 @@
#include <poll.h>
#include <stdlib.h>
+#include <stddef.h>
+#include <stdio.h>
#include "cache.h"
@@ -62,6 +64,7 @@ vbe_NewBusyObj(void)
ALLOC_OBJ(busyobj, BUSYOBJ_MAGIC);
AN(busyobj);
+ Lck_New(&busyobj->mtx, lck_busyobj);
return (busyobj);
}
@@ -70,6 +73,7 @@ vbe_FreeBusyObj(struct busyobj *busyobj)
{
CHECK_OBJ_NOTNULL(busyobj, BUSYOBJ_MAGIC);
AZ(busyobj->refcount);
+ Lck_Delete(&busyobj->mtx);
FREE_OBJ(busyobj);
}
@@ -83,8 +87,8 @@ VBE_GetBusyObj(void)
CHECK_OBJ_NOTNULL(nbusyobj, BUSYOBJ_MAGIC);
busyobj = nbusyobj;
nbusyobj = NULL;
- memset(busyobj, 0, sizeof *busyobj);
- busyobj->magic = BUSYOBJ_MAGIC;
+ memset((char *)busyobj + offsetof(struct busyobj, refcount), 0,
+ sizeof *busyobj - offsetof(struct busyobj, refcount));
}
Lck_Unlock(&nbusyobj_mtx);
if (busyobj == NULL)
@@ -98,8 +102,10 @@ struct busyobj *
VBE_RefBusyObj(struct busyobj *busyobj)
{
CHECK_OBJ_NOTNULL(busyobj, BUSYOBJ_MAGIC);
+ Lck_Lock(&busyobj->mtx);
assert(busyobj->refcount > 0);
busyobj->refcount++;
+ Lck_Unlock(&busyobj->mtx);
return (busyobj);
}
@@ -110,12 +116,18 @@ VBE_DerefBusyObj(struct busyobj **pbo)
busyobj = *pbo;
CHECK_OBJ_NOTNULL(busyobj, BUSYOBJ_MAGIC);
+ Lck_Lock(&busyobj->mtx);
assert(busyobj->refcount > 0);
busyobj->refcount--;
*pbo = NULL;
- if (busyobj->refcount > 0)
+ if (busyobj->refcount > 0) {
+ Lck_Unlock(&busyobj->mtx);
return;
+ }
+ Lck_Unlock(&busyobj->mtx);
+
/* XXX Sanity checks e.g. AZ(busyobj->vbc) */
+
Lck_Lock(&nbusyobj_mtx);
if (nbusyobj == NULL) {
nbusyobj = busyobj;
diff --git a/include/tbl/locks.h b/include/tbl/locks.h
index 2ad717d..d86da01 100644
--- a/include/tbl/locks.h
+++ b/include/tbl/locks.h
@@ -50,4 +50,5 @@ LOCK(vbe)
LOCK(backend)
LOCK(vcapace)
LOCK(nbusyobj)
+LOCK(busyobj)
/*lint -restore */
More information about the varnish-commit
mailing list