aboutsummaryrefslogtreecommitdiffstats
path: root/include/osmocom/core/timer_compat.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/osmocom/core/timer_compat.h')
-rw-r--r--include/osmocom/core/timer_compat.h44
1 files changed, 44 insertions, 0 deletions
diff --git a/include/osmocom/core/timer_compat.h b/include/osmocom/core/timer_compat.h
index fb2967ba..7e1e7235 100644
--- a/include/osmocom/core/timer_compat.h
+++ b/include/osmocom/core/timer_compat.h
@@ -72,5 +72,49 @@
} while (0)
#endif
+/* Convenience macros for operations on timespecs.
+ NOTE: `timercmp' does not work for >= or <=. */
+
+#ifndef timespecisset
+# define timespecisset(tvp) ((tvp)->tv_sec || (tvp)->tv_nsec)
+#endif
+
+#ifndef timespecclear
+# define timespecclear(tvp) ((tvp)->tv_sec = (tvp)->tv_nsec = 0)
+#endif
+
+#ifndef timespeccmp
+# define timespeccmp(a, b, CMP) \
+ (((a)->tv_sec == (b)->tv_sec) ? \
+ ((a)->tv_nsec CMP (b)->tv_nsec) : \
+ ((a)->tv_sec CMP (b)->tv_sec))
+#endif
+
+#ifndef timespecadd
+# define timespecadd(a, b, result) \
+ do { \
+ (result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \
+ (result)->tv_nsec = (a)->tv_nsec + (b)->tv_nsec; \
+ if ((result)->tv_nsec >= 1000000000) \
+ { \
+ ++(result)->tv_sec; \
+ (result)->tv_nsec -= 1000000000; \
+ } \
+ } while (0)
+#endif
+
+#ifndef timespecsub
+# define timespecsub(a, b, result) \
+ do { \
+ (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
+ (result)->tv_nsec = (a)->tv_nsec - (b)->tv_nsec; \
+ if ((result)->tv_nsec < 0) { \
+ --(result)->tv_sec; \
+ (result)->tv_nsec += 1000000000; \
+ } \
+ } while (0)
+#endif
+
+
/*! @} */