Mailing List Archive

[master] 150f9fd56 cocci: Add a patch for VTIM_timespec() refactoring
commit 150f9fd56390a722395d3d31fe1f68c1d577f33e
Author: Dridi Boukelmoune <dridi.boukelmoune@gmail.com>
Date: Mon Oct 25 16:31:37 2021 +0200

cocci: Add a patch for VTIM_timespec() refactoring

Already archived since there are no more occurrences in trunk, but it
could be useful on other branches or third-party libvarnish consumers.

The coccinelle patch also takes care of the recent manual refactoring.

Refs 4ae73a5b19ec1fc87cc018c01757535667e33341
Refs cf00dd2ed96c9b7a2ccd02846d9bc55719b9b919

diff --git a/bin/varnishd/waiter/cache_waiter_kqueue.c b/bin/varnishd/waiter/cache_waiter_kqueue.c
index 8e70af060..b0f097c1b 100644
--- a/bin/varnishd/waiter/cache_waiter_kqueue.c
+++ b/bin/varnishd/waiter/cache_waiter_kqueue.c
@@ -104,8 +104,7 @@ vwk_thread(void *priv)
Wait_Call(w, wp, WAITER_TIMEOUT, now);
}
then = vwk->next - now;
- ts.tv_sec = (time_t)floor(then);
- ts.tv_nsec = (long)(1e9 * (then - ts.tv_sec));
+ ts = VTIM_timespec(then);
Lck_Unlock(&vwk->mtx);
n = kevent(vwk->kq, NULL, 0, ke, NKEV, &ts);
assert(n >= 0);
diff --git a/bin/varnishd/waiter/cache_waiter_ports.c b/bin/varnishd/waiter/cache_waiter_ports.c
index 6ae65290c..362a4d940 100644
--- a/bin/varnishd/waiter/cache_waiter_ports.c
+++ b/bin/varnishd/waiter/cache_waiter_ports.c
@@ -174,8 +174,7 @@ vws_thread(void *priv)
Wait_Call(w, wp, WAITER_TIMEOUT, now);
}
then = vws->next - now;
- ts.tv_sec = (time_t)floor(then);
- ts.tv_nsec = (long)(1e9 * (then - ts.tv_sec));
+ ts = VTIM_timespec(then);

/*
* min number of events we accept. could consider to scale up
diff --git a/tools/coccinelle/archive/vtim_timespec.cocci b/tools/coccinelle/archive/vtim_timespec.cocci
new file mode 100644
index 000000000..0e5d561f6
--- /dev/null
+++ b/tools/coccinelle/archive/vtim_timespec.cocci
@@ -0,0 +1,23 @@
+/*
+ * This patch refactors to VTIM_timespec().
+ */
+
+@@
+expression fval, fmod;
+struct timespec ts;
+type t1, t2;
+@@
+
+- ts.tv_nsec = (t1)(modf(fval, &fmod) * 1e9);
+- ts.tv_sec = (t2)fmod;
++ ts = VTIM_timespec(fval);
+
+@@
+expression fval;
+struct timespec ts;
+type t1, t2;
+@@
+
+- ts.tv_sec = (t1)floor(fval);
+- ts.tv_nsec = (t2)(1e9 * (fval - ts.tv_sec));
++ ts = VTIM_timespec(fval);
_______________________________________________
varnish-commit mailing list
varnish-commit@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-commit