[master] 1638ff0a6 Move the locking calls outside exp_mail_it

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Fri Jun 12 13:25:07 UTC 2020


commit 1638ff0a64a3deabfd1be9416d10e79db7e026c8
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date:   Thu Mar 19 11:08:50 2020 +0100

    Move the locking calls outside exp_mail_it
    
    This enables doing extra handling while holding the mutex specific to
    EXP_Insert/EXP_Remove before/after calling exp_mail_it.

diff --git a/bin/varnishd/cache/cache_expire.c b/bin/varnishd/cache/cache_expire.c
index 2ed544dc2..293ced626 100644
--- a/bin/varnishd/cache/cache_expire.c
+++ b/bin/varnishd/cache/cache_expire.c
@@ -106,7 +106,8 @@ exp_mail_it(struct objcore *oc, uint8_t cmds)
 	CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
 	assert(oc->refcnt > 0);
 
-	Lck_Lock(&exphdl->mtx);
+	Lck_AssertHeld(&exphdl->mtx);
+
 	if ((cmds | oc->exp_flags) & OC_EF_REFD) {
 		if (!(oc->exp_flags & OC_EF_POSTED)) {
 			if (cmds & OC_EF_REMOVE)
@@ -121,7 +122,6 @@ exp_mail_it(struct objcore *oc, uint8_t cmds)
 		VSC_C_main->exp_mailed++;
 		AZ(pthread_cond_signal(&exphdl->condvar));
 	}
-	Lck_Unlock(&exphdl->mtx);
 }
 
 /*--------------------------------------------------------------------
@@ -133,8 +133,11 @@ EXP_Remove(struct objcore *oc)
 {
 
 	CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
-	if (oc->exp_flags & OC_EF_REFD)
+	if (oc->exp_flags & OC_EF_REFD) {
+		Lck_Lock(&exphdl->mtx);
 		exp_mail_it(oc, OC_EF_REMOVE);
+		Lck_Unlock(&exphdl->mtx);
+	}
 }
 
 /*--------------------------------------------------------------------
@@ -151,11 +154,13 @@ EXP_Insert(struct worker *wrk, struct objcore *oc)
 	CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
 	assert(oc->refcnt >= 2);
 
-	AZ(oc->exp_flags & (OC_EF_INSERT | OC_EF_MOVE));
 	AZ(oc->flags & OC_F_DYING);
 
 	ObjSendEvent(wrk, oc, OEV_INSERT);
+	Lck_Lock(&exphdl->mtx);
+	AZ(oc->exp_flags & (OC_EF_INSERT | OC_EF_MOVE));
 	exp_mail_it(oc, OC_EF_INSERT | OC_EF_REFD | OC_EF_MOVE);
+	Lck_Unlock(&exphdl->mtx);
 }
 
 /*--------------------------------------------------------------------
@@ -187,8 +192,11 @@ EXP_Rearm(struct objcore *oc, vtim_real now,
 	VSL(SLT_ExpKill, 0, "EXP_Rearm p=%p E=%.6f e=%.6f f=0x%x", oc,
 	    oc->timer_when, when, oc->flags);
 
-	if (when < oc->t_origin || when < oc->timer_when)
+	if (when < oc->t_origin || when < oc->timer_when) {
+		Lck_Lock(&exphdl->mtx);
 		exp_mail_it(oc, OC_EF_MOVE);
+		Lck_Unlock(&exphdl->mtx);
+	}
 }
 
 /*--------------------------------------------------------------------


More information about the varnish-commit mailing list