[master] dd65da676 varnishd: Apply usleep.cocci

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Wed Feb 5 16:56:06 UTC 2025


commit dd65da6765105762e6d4e19b3586f65d0a678c6e
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Wed Feb 5 17:45:39 2025 +0100

    varnishd: Apply usleep.cocci

diff --git a/bin/varnishd/cache/cache_conn_pool.c b/bin/varnishd/cache/cache_conn_pool.c
index f510e3b68..300ba66da 100644
--- a/bin/varnishd/cache/cache_conn_pool.c
+++ b/bin/varnishd/cache/cache_conn_pool.c
@@ -380,7 +380,7 @@ VCP_Recycle(const struct worker *wrk, struct pfd **pfdp)
 		 * have N+1 backend connections rather than N, which is
 		 * entirely harmless.
 		 */
-		(void)usleep(10000);
+		VTIM_sleep(0.01);
 	}
 }
 
diff --git a/bin/varnishd/cache/cache_lck.c b/bin/varnishd/cache/cache_lck.c
index 029ecc8c9..b4582eee9 100644
--- a/bin/varnishd/cache/cache_lck.c
+++ b/bin/varnishd/cache/cache_lck.c
@@ -268,7 +268,7 @@ Lck_CondWaitUntil(pthread_cond_t *cond, struct lock *lck, vtim_real when)
 		 * 20220329 /phk
 		 */
 		if (errno == EINVAL) {
-			usleep(100);
+			VTIM_sleep(0.0001);
 			errno = pthread_cond_timedwait(cond, &ilck->mtx, &ts);
 		}
 #endif
diff --git a/bin/varnishd/cache/cache_pool.c b/bin/varnishd/cache/cache_pool.c
index 53d00a5b8..d3642c942 100644
--- a/bin/varnishd/cache/cache_pool.c
+++ b/bin/varnishd/cache/cache_pool.c
@@ -166,7 +166,7 @@ pool_mkpool(unsigned pool_no)
 	PTOK(pthread_create(&pp->herder_thr, NULL, pool_herder, pp));
 
 	while (VTAILQ_EMPTY(&pp->idle_queue))
-		(void)usleep(10000);
+		VTIM_sleep(0.01);
 
 	SES_NewPool(pp, pool_no);
 	VCA_NewPool(pp);
@@ -282,5 +282,5 @@ Pool_Init(void)
 	Lck_New(&pool_mtx, lck_wq);
 	PTOK(pthread_create(&thr_pool_herder, NULL, pool_poolherder, NULL));
 	while (!VSC_C_main->pools)
-		(void)usleep(10000);
+		VTIM_sleep(0.01);
 }
diff --git a/bin/varnishd/cache/cache_vrt_vcl.c b/bin/varnishd/cache/cache_vrt_vcl.c
index b021e2280..b4e77d158 100644
--- a/bin/varnishd/cache/cache_vrt_vcl.c
+++ b/bin/varnishd/cache/cache_vrt_vcl.c
@@ -83,7 +83,7 @@ VCL_Refresh(struct vcl **vcc)
 {
 
 	while (vcl_active == NULL)
-		(void)usleep(100000);
+		VTIM_sleep(0.1);
 
 	ASSERT_VCL_ACTIVE();
 	if (*vcc == vcl_active)
diff --git a/bin/varnishd/http1/cache_http1_pipe.c b/bin/varnishd/http1/cache_http1_pipe.c
index e361ba020..32d7471fe 100644
--- a/bin/varnishd/http1/cache_http1_pipe.c
+++ b/bin/varnishd/http1/cache_http1_pipe.c
@@ -63,7 +63,7 @@ rdf(int fd0, int fd1, uint64_t *pcnt)
 			return (1);
 		*pcnt += j;
 		if (i != j)
-			(void)usleep(100000);		/* XXX hack */
+			VTIM_sleep(0.1);		/* XXX hack */
 	}
 	return (0);
 }
diff --git a/bin/varnishd/mgt/mgt_child.c b/bin/varnishd/mgt/mgt_child.c
index eadd65f0c..58f0e80b7 100644
--- a/bin/varnishd/mgt/mgt_child.c
+++ b/bin/varnishd/mgt/mgt_child.c
@@ -555,7 +555,7 @@ mgt_reap_child(void)
 		r = waitpid(child_pid, &status, WNOHANG);
 		if (r == child_pid)
 			break;
-		(void)usleep(100000);
+		VTIM_sleep(0.1);
 	}
 	if (r == 0) {
 		VSB_printf(vsb, "Child (%jd) not dying (waitpid = %jd),"
diff --git a/bin/varnishd/waiter/cache_waiter_poll.c b/bin/varnishd/waiter/cache_waiter_poll.c
index e9c017bf2..26d1c8739 100644
--- a/bin/varnishd/waiter/cache_waiter_poll.c
+++ b/bin/varnishd/waiter/cache_waiter_poll.c
@@ -259,7 +259,7 @@ vwp_fini(struct waiter *w)
 	CAST_OBJ_NOTNULL(vwp, w->priv, VWP_MAGIC);
 	vp = NULL;
 	while (vwp->hpoll > 1)
-		(void)usleep(100000);
+		VTIM_sleep(0.1);
 	// XXX: set write pipe blocking
 	assert(write(vwp->pipes[1], &vp, sizeof vp) == sizeof vp);
 	PTOK(pthread_join(vwp->thread, &vp));


More information about the varnish-commit mailing list