[6.0] abb63ed7f Change hash slingers deref func to take a locked objhead
Dridi Boukelmoune
dridi.boukelmoune at gmail.com
Fri Feb 8 13:13:10 UTC 2019
commit abb63ed7f32db2aaa7437e0bb59f65b648871a60
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 fd0deeb19..9468504d5 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