[master] a26123f31 lck: Apply "never" timeouts to cond waits

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Tue Mar 5 08:53:10 UTC 2024


commit a26123f31c9171ba01a8243d9ffa64334090c0b8
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Fri Mar 1 10:41:29 2024 +0100

    lck: Apply "never" timeouts to cond waits
    
    The vtim_real in Lck_CondWaitUntil() is not meant to be INFINITY, and it
    should only apply to the vtim_dur passed to Lck_CondWaitTimeout(). In
    practice it does since the latter calls the former. It could be enforced
    by extracting a static function from Lck_CondWaitUntil().
    
    This accommodates a few timeout parameters that are used for cond waits.

diff --git a/bin/varnishd/cache/cache_lck.c b/bin/varnishd/cache/cache_lck.c
index 8f33dee8c..5c7ab42ce 100644
--- a/bin/varnishd/cache/cache_lck.c
+++ b/bin/varnishd/cache/cache_lck.c
@@ -209,19 +209,20 @@ Lck__Owned(const struct lock *lck)
 int v_matchproto_()
 Lck_CondWait(pthread_cond_t *cond, struct lock *lck)
 {
-       return (Lck_CondWaitUntil(cond, lck, 0));
+       return (Lck_CondWaitUntil(cond, lck, INFINITY));
 }
 
 int v_matchproto_()
 Lck_CondWaitTimeout(pthread_cond_t *cond, struct lock *lck, vtim_dur timeout)
 {
-	assert(timeout >= 0);
-	assert(timeout < 3600);
 
-	if (timeout == 0)
-		return (Lck_CondWaitUntil(cond, lck, 0));
-	else
-		return (Lck_CondWaitUntil(cond, lck, VTIM_real() + timeout));
+	if (isinf(timeout))
+		return (Lck_CondWaitUntil(cond, lck, INFINITY));
+
+	assert(timeout >= 0);
+	assert(timeout <= 3600);
+	timeout = vmax(timeout, 1e-3);
+	return (Lck_CondWaitUntil(cond, lck, VTIM_real() + timeout));
 }
 
 int v_matchproto_()
@@ -235,7 +236,7 @@ Lck_CondWaitUntil(pthread_cond_t *cond, struct lock *lck, vtim_real when)
 	AN(ilck->held);
 	assert(pthread_equal(ilck->owner, pthread_self()));
 	ilck->held = 0;
-	if (when == 0) {
+	if (isinf(when)) {
 		errno = pthread_cond_wait(cond, &ilck->mtx);
 		AZ(errno);
 	} else {
diff --git a/bin/varnishd/cache/cache_wrk.c b/bin/varnishd/cache/cache_wrk.c
index 8803b5048..971904337 100644
--- a/bin/varnishd/cache/cache_wrk.c
+++ b/bin/varnishd/cache/cache_wrk.c
@@ -443,7 +443,7 @@ Pool_Work_Thread(struct pool *pp, struct worker *wrk)
 					 * chance to push stats. */
 					tmo = now + 1.;
 				else if (wrk->wpriv->vcl == NULL)
-					tmo = 0;
+					tmo = INFINITY;
 				else if (DO_DEBUG(DBG_VTC_MODE))
 					tmo = now + 1.;
 				else


More information about the varnish-commit mailing list