aboutsummaryrefslogtreecommitdiff
path: root/src/lib/wallclock/timeval.h
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2019-05-15 08:28:25 -0400
committerNick Mathewson <nickm@torproject.org>2019-05-23 12:48:51 -0400
commitb88281024579d5f207d15d1a2cc54c113f8a2bde (patch)
tree8d5e7d08006242879fa90706f2f51024db41f6ef /src/lib/wallclock/timeval.h
parent2bb5d8148b2c15e9573a7f041ef631bdf4429b4b (diff)
downloadtor-b88281024579d5f207d15d1a2cc54c113f8a2bde.tar.gz
tor-b88281024579d5f207d15d1a2cc54c113f8a2bde.zip
In coverage builds, use branch-free timeradd() and timersub()
The ordinary definitions of timeradd() and timersub() contain a branch. However, in coverage builds, this means that we get spurious complaints about partially covered basic blocks, in a way that makes our coverage determinism harder to check.
Diffstat (limited to 'src/lib/wallclock/timeval.h')
-rw-r--r--src/lib/wallclock/timeval.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/lib/wallclock/timeval.h b/src/lib/wallclock/timeval.h
index 4967e939bf..33076adc8b 100644
--- a/src/lib/wallclock/timeval.h
+++ b/src/lib/wallclock/timeval.h
@@ -20,6 +20,27 @@
#include <sys/time.h>
#endif
+#ifdef TOR_COVERAGE
+/* For coverage builds, we use a slower definition of these macros without
+ * branches, to make coverage consistent. */
+#undef timeradd
+#undef timersub
+#define timeradd(tv1,tv2,tvout) \
+ do { \
+ (tvout)->tv_sec = (tv1)->tv_sec + (tv2)->tv_sec; \
+ (tvout)->tv_usec = (tv1)->tv_usec + (tv2)->tv_usec; \
+ (tvout)->tv_sec += (tvout)->tv_usec / 1000000; \
+ (tvout)->tv_usec %= 1000000; \
+ } while (0)
+#define timersub(tv1,tv2,tvout) \
+ do { \
+ (tvout)->tv_sec = (tv1)->tv_sec - (tv2)->tv_sec - 1; \
+ (tvout)->tv_usec = (tv1)->tv_usec - (tv2)->tv_usec + 1000000; \
+ (tvout)->tv_sec += (tvout)->tv_usec / 1000000; \
+ (tvout)->tv_usec %= 1000000; \
+ } while (0)
+#endif
+
#ifndef timeradd
/** Replacement for timeradd on platforms that do not have it: sets tvout to
* the sum of tv1 and tv2. */