[6.0] e4c302679 Add hsh_deref_objhead_unlock(), taking a locked objhead

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Fri Feb 8 13:13:10 UTC 2019


commit e4c3026796dede208efd7dcb547ab9c2068cfc6d
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date:   Tue Dec 4 10:57:11 2018 +0100

    Add hsh_deref_objhead_unlock(), taking a locked objhead
    
    Split hsh_deref_objhead() into two parts, with the new
    hsh_deref_objhead_unlock() function expecting a locked objhead reference
    on input.

diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c
index 80a8a6f92..5a13bffd0 100644
--- a/bin/varnishd/cache/cache_hash.c
+++ b/bin/varnishd/cache/cache_hash.c
@@ -77,6 +77,7 @@ static void hsh_rush1(const struct worker *, struct objhead *,
     struct rush *, int);
 static void hsh_rush2(struct worker *, struct rush *);
 static int hsh_deref_objhead(struct worker *wrk, struct objhead **poh);
+static int hsh_deref_objhead_unlock(struct worker *wrk, struct objhead **poh);
 
 /*---------------------------------------------------------------------*/
 
@@ -979,7 +980,7 @@ HSH_DerefObjCore(struct worker *wrk, struct objcore **ocp, int rushmax)
 }
 
 static int
-hsh_deref_objhead(struct worker *wrk, struct objhead **poh)
+hsh_deref_objhead_unlock(struct worker *wrk, struct objhead **poh)
 {
 	struct objhead *oh;
 	struct rush rush;
@@ -988,9 +989,10 @@ hsh_deref_objhead(struct worker *wrk, struct objhead **poh)
 	TAKE_OBJ_NOTNULL(oh, poh, OBJHEAD_MAGIC);
 	INIT_OBJ(&rush, RUSH_MAGIC);
 
+	Lck_AssertHeld(&oh->mtx);
+
 	if (oh == private_oh) {
 		assert(VTAILQ_EMPTY(&oh->waitinglist));
-		Lck_Lock(&oh->mtx);
 		assert(oh->refcnt > 1);
 		oh->refcnt--;
 		Lck_Unlock(&oh->mtx);
@@ -1005,7 +1007,6 @@ hsh_deref_objhead(struct worker *wrk, struct objhead **poh)
 	 * just make the hold the same ref's as objcore, that would
 	 * confuse hashers.
 	 */
-	Lck_Lock(&oh->mtx);
 	while (oh->refcnt == 1 && !VTAILQ_EMPTY(&oh->waitinglist)) {
 		hsh_rush1(wrk, oh, &rush, HSH_RUSH_ALL);
 		Lck_Unlock(&oh->mtx);
@@ -1017,6 +1018,18 @@ hsh_deref_objhead(struct worker *wrk, struct objhead **poh)
 	return (hash->deref(wrk, oh));
 }
 
+static int
+hsh_deref_objhead(struct worker *wrk, struct objhead **poh)
+{
+	struct objhead *oh;
+
+	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
+	TAKE_OBJ_NOTNULL(oh, poh, OBJHEAD_MAGIC);
+
+	Lck_Lock(&oh->mtx);
+	return (hsh_deref_objhead_unlock(wrk, &oh));
+}
+
 void
 HSH_Init(const struct hash_slinger *slinger)
 {


More information about the varnish-commit mailing list