[master] caf49d8b4 transit buffer without the timeout on the condition variable

Nils Goroll nils.goroll at uplex.de
Mon Nov 7 14:58:05 UTC 2022

commit caf49d8b42b97c3599e01f2e503d24991a1a0bcf
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Wed Jun 1 12:55:09 2022 +0200

    transit buffer without the timeout on the condition variable
    We do not need to periodically check the conditions in
    obj_extend_condwait() if we ensure that HSH_Cancel() triggers a
    Readers on private objects need to ensure they call HSH_Cancel() if
    they abort the read, so this is consistent with our requirements.
    While we could add a seperate function to the object API for the sole
    purpose of signaling a cancel, HSH_Cancel() already calls
    ObjWaitState() to syncronize with the backend thread, so adding the
    signal there was deemed the simpler solution.
    As agreed during bugwash, Martin wants to add back the timeout
    as an optinal parameter (default: no timeout).

diff --git a/bin/varnishd/cache/cache_obj.c b/bin/varnishd/cache/cache_obj.c
index b839b9e68..b862d2c44 100644
--- a/bin/varnishd/cache/cache_obj.c
+++ b/bin/varnishd/cache/cache_obj.c
@@ -232,12 +232,8 @@ obj_extend_condwait(const struct objcore *oc)
 	 * updates to delivered_so_far after timing out.
 	while (!(oc->flags & OC_F_CANCEL) && oc->boc->fetched_so_far >
-	    oc->boc->delivered_so_far + oc->boc->transit_buffer) {
-		(void)Lck_CondWaitTimeout(&oc->boc->cond, &oc->boc->mtx, 0.1);
-		/* Fallback: Check if we are alone waiting on this object */
-		if (oc->refcnt == 1)
-			break;
-	}
+	    oc->boc->delivered_so_far + oc->boc->transit_buffer)
+		(void)Lck_CondWait(&oc->boc->cond, &oc->boc->mtx);
@@ -334,6 +330,9 @@ ObjWaitState(const struct objcore *oc, enum boc_state_e want)
+	/* wake up obj_extend_condwait() */
+	if (oc->flags & OC_F_CANCEL)
+		AZ(pthread_cond_signal(&oc->boc->cond));
 	while (1) {
 		if (oc->boc->state >= want)

More information about the varnish-commit mailing list