[6.0] e2d1a6504 Move HSH_DeleteObjHead into the hash deref methods
Dridi Boukelmoune
dridi.boukelmoune at gmail.com
Fri Feb 8 13:13:10 UTC 2019
commit e2d1a6504539fb111b69732ee1feb57719db65a3
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date: Tue Nov 20 12:48:49 2018 +0100
Move HSH_DeleteObjHead into the hash deref methods
Move the clean up call to HSH_DeleteObjHead inside of the hash deref
methods that require it, instead of having the outside (single) caller do
it based off the return value. This just cleans up and makes the logic
more transparent.
diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c
index 64c12686d..fd0deeb19 100644
--- a/bin/varnishd/cache/cache_hash.c
+++ b/bin/varnishd/cache/cache_hash.c
@@ -983,7 +983,6 @@ HSH_DerefObjHead(struct worker *wrk, struct objhead **poh)
{
struct objhead *oh;
struct rush rush;
- int r;
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
TAKE_OBJ_NOTNULL(oh, poh, OBJHEAD_MAGIC);
@@ -1016,10 +1015,7 @@ HSH_DerefObjHead(struct worker *wrk, struct objhead **poh)
Lck_Unlock(&oh->mtx);
assert(oh->refcnt > 0);
- r = hash->deref(oh);
- if (!r)
- HSH_DeleteObjHead(wrk, oh);
- return (r);
+ return (hash->deref(wrk, oh));
}
void
diff --git a/bin/varnishd/hash/hash_classic.c b/bin/varnishd/hash/hash_classic.c
index 3440b9bd2..d3303c875 100644
--- a/bin/varnishd/hash/hash_classic.c
+++ b/bin/varnishd/hash/hash_classic.c
@@ -172,7 +172,7 @@ hcl_lookup(struct worker *wrk, const void *digest, struct objhead **noh)
*/
static int v_matchproto_(hash_deref_f)
-hcl_deref(struct objhead *oh)
+hcl_deref(struct worker *wrk, struct objhead *oh)
{
struct hcl_hd *hp;
int ret;
@@ -187,6 +187,8 @@ hcl_deref(struct objhead *oh)
} else
ret = 1;
Lck_Unlock(&hp->mtx);
+ if (!ret)
+ HSH_DeleteObjHead(wrk, oh);
return (ret);
}
diff --git a/bin/varnishd/hash/hash_critbit.c b/bin/varnishd/hash/hash_critbit.c
index c673595b2..1c453148f 100644
--- a/bin/varnishd/hash/hash_critbit.c
+++ b/bin/varnishd/hash/hash_critbit.c
@@ -347,13 +347,15 @@ hcb_start(void)
}
static int v_matchproto_(hash_deref_f)
-hcb_deref(struct objhead *oh)
+hcb_deref(struct worker *wrk, struct objhead *oh)
{
+ int r;
+ (void)wrk;
CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC);
Lck_Lock(&oh->mtx);
assert(oh->refcnt > 0);
- oh->refcnt--;
+ r = --oh->refcnt;
if (oh->refcnt == 0) {
Lck_Lock(&hcb_mtx);
hcb_delete(&hcb_root, oh);
@@ -364,7 +366,7 @@ hcb_deref(struct objhead *oh)
#ifdef PHK
fprintf(stderr, "hcb_defef %d %d <%s>\n", __LINE__, r, oh->hash);
#endif
- return (1);
+ return (r);
}
static struct objhead * v_matchproto_(hash_lookup_f)
diff --git a/bin/varnishd/hash/hash_simple_list.c b/bin/varnishd/hash/hash_simple_list.c
index 4c1e9025a..643148ed0 100644
--- a/bin/varnishd/hash/hash_simple_list.c
+++ b/bin/varnishd/hash/hash_simple_list.c
@@ -108,7 +108,7 @@ hsl_lookup(struct worker *wrk, const void *digest, struct objhead **noh)
*/
static int v_matchproto_(hash_deref_f)
-hsl_deref(struct objhead *oh)
+hsl_deref(struct worker *wrk, struct objhead *oh)
{
int ret;
@@ -119,6 +119,8 @@ hsl_deref(struct objhead *oh)
} else
ret = 1;
Lck_Unlock(&hsl_mtx);
+ if (!ret)
+ HSH_DeleteObjHead(wrk, oh);
return (ret);
}
diff --git a/bin/varnishd/hash/hash_slinger.h b/bin/varnishd/hash/hash_slinger.h
index 6c17b8374..0ff95cca2 100644
--- a/bin/varnishd/hash/hash_slinger.h
+++ b/bin/varnishd/hash/hash_slinger.h
@@ -36,7 +36,7 @@ typedef void hash_start_f(void);
typedef void hash_prep_f(struct worker *);
typedef struct objhead *hash_lookup_f(struct worker *, const void *digest,
struct objhead **);
-typedef int hash_deref_f(struct objhead *);
+typedef int hash_deref_f(struct worker *, struct objhead *);
struct hash_slinger {
unsigned magic;
More information about the varnish-commit
mailing list