[master] 5f97b89a1 Avoid lock/unlock/lock/unlock for cluster delete
Poul-Henning Kamp
phk at FreeBSD.org
Thu Aug 1 07:40:10 UTC 2019
commit 5f97b89a136a76932c41bf42d91a823a4a4e2e02
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Thu Aug 1 07:33:40 2019 +0000
Avoid lock/unlock/lock/unlock for cluster delete
diff --git a/bin/varnishd/common/common_vsmw.c b/bin/varnishd/common/common_vsmw.c
index 8e22756f0..6d8a17e4a 100644
--- a/bin/varnishd/common/common_vsmw.c
+++ b/bin/varnishd/common/common_vsmw.c
@@ -281,7 +281,6 @@ VSMW_DestroyCluster(struct vsmw *vsmw, struct vsmw_cluster **vsmcp)
{
struct vsmw_cluster *vc;
- vsmw_lock();
CHECK_OBJ_NOTNULL(vsmw, VSMW_MAGIC);
TAKE_OBJ_NOTNULL(vc, vsmcp, VSMW_CLUSTER_MAGIC);
@@ -294,10 +293,8 @@ VSMW_DestroyCluster(struct vsmw *vsmw, struct vsmw_cluster **vsmcp)
*/
vsmw_delseg(vsmw, vc->cseg, 1);
vc->cseg = NULL;
- if (vc->refs > 0) {
- vsmw_unlock();
+ if (vc->refs > 0)
return;
- }
}
AZ(munmap(vc->ptr, vc->len));
@@ -307,7 +304,6 @@ VSMW_DestroyCluster(struct vsmw *vsmw, struct vsmw_cluster **vsmcp)
assert (errno == ENOENT);
REPLACE(vc->fn, NULL);
FREE_OBJ(vc);
- vsmw_unlock();
}
/*--------------------------------------------------------------------*/
@@ -369,26 +365,24 @@ void
VSMW_Free(struct vsmw *vsmw, void **pp)
{
struct vsmwseg *seg;
- void *p;
+ struct vsmw_cluster *cp;
vsmw_lock();
CHECK_OBJ_NOTNULL(vsmw, VSMW_MAGIC);
AN(pp);
- p = *pp;
- AN(p);
- *pp = NULL;
VTAILQ_FOREACH(seg, &vsmw->segs, list)
- if (seg->ptr == p)
+ if (seg->ptr == *pp)
break;
AN(seg);
+ *pp = NULL;
- if (!--seg->cluster->refs && seg->cluster->cseg == NULL) {
- vsmw_unlock();
- VSMW_DestroyCluster(vsmw, &seg->cluster);
- vsmw_lock();
- }
+ cp = seg->cluster;
vsmw_delseg(vsmw, seg, 1);
+
+ if (!--cp->refs && cp->cseg == NULL)
+ VSMW_DestroyCluster(vsmw, &cp);
+
vsmw_unlock();
}
More information about the varnish-commit
mailing list