[master] b420840d1 Change hash slingers deref func to take a locked objhead

Martin Blix Grydeland martin at varnish-software.com
Tue Dec 4 13:46:08 UTC 2018


commit b420840d1bade47cef3ecbb724757cea158e8475
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date:   Tue Nov 20 12:59:36 2018 +0100

    Change hash slingers deref func to take a locked objhead
    
    This changes the hash slingers deref function to take a locked objhead on
    input, and unlocking it before returning. This saves a lock/unlock
    sequence for critbit (which is the critical one) on HSH_DerefObjHead.

diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c
index 18bbd7a07..4a430f3e3 100644
--- a/bin/varnishd/cache/cache_hash.c
+++ b/bin/varnishd/cache/cache_hash.c
@@ -1012,7 +1012,6 @@ HSH_DerefObjHead(struct worker *wrk, struct objhead **poh)
 		hsh_rush2(wrk, &rush);
 		Lck_Lock(&oh->mtx);
 	}
-	Lck_Unlock(&oh->mtx);
 
 	assert(oh->refcnt > 0);
 	return (hash->deref(wrk, oh));
diff --git a/bin/varnishd/hash/hash_classic.c b/bin/varnishd/hash/hash_classic.c
index d3303c875..cb3b0b3a2 100644
--- a/bin/varnishd/hash/hash_classic.c
+++ b/bin/varnishd/hash/hash_classic.c
@@ -178,6 +178,9 @@ hcl_deref(struct worker *wrk, struct objhead *oh)
 	int ret;
 
 	CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC);
+	Lck_AssertHeld(&oh->mtx);
+	Lck_Unlock(&oh->mtx);
+
 	CAST_OBJ_NOTNULL(hp, oh->hoh_head, HCL_HEAD_MAGIC);
 	assert(oh->refcnt > 0);
 	Lck_Lock(&hp->mtx);
diff --git a/bin/varnishd/hash/hash_critbit.c b/bin/varnishd/hash/hash_critbit.c
index 1c453148f..fcedbef5f 100644
--- a/bin/varnishd/hash/hash_critbit.c
+++ b/bin/varnishd/hash/hash_critbit.c
@@ -353,7 +353,7 @@ hcb_deref(struct worker *wrk, struct objhead *oh)
 
 	(void)wrk;
 	CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC);
-	Lck_Lock(&oh->mtx);
+	Lck_AssertHeld(&oh->mtx);
 	assert(oh->refcnt > 0);
 	r = --oh->refcnt;
 	if (oh->refcnt == 0) {
diff --git a/bin/varnishd/hash/hash_simple_list.c b/bin/varnishd/hash/hash_simple_list.c
index 643148ed0..8c0858e18 100644
--- a/bin/varnishd/hash/hash_simple_list.c
+++ b/bin/varnishd/hash/hash_simple_list.c
@@ -112,6 +112,10 @@ hsl_deref(struct worker *wrk, struct objhead *oh)
 {
 	int ret;
 
+	CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC);
+	Lck_AssertHeld(&oh->mtx);
+	Lck_Unlock(&oh->mtx);
+
 	Lck_Lock(&hsl_mtx);
 	if (--oh->refcnt == 0) {
 		VTAILQ_REMOVE(&hsl_head, oh, hoh_list);


More information about the varnish-commit mailing list