summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/Makefile.am2
-rw-r--r--include/osmocom/core/timer_compat.h44
2 files changed, 45 insertions, 1 deletions
diff --git a/include/Makefile.am b/include/Makefile.am
index f95d90c7..8b05f80b 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -47,6 +47,7 @@ nobase_include_HEADERS = \
osmocom/core/strrb.h \
osmocom/core/talloc.h \
osmocom/core/timer.h \
+ osmocom/core/timer_compat.h \
osmocom/core/utils.h \
osmocom/core/write_queue.h \
osmocom/crypt/auth.h \
@@ -148,7 +149,6 @@ nobase_include_HEADERS += \
endif
noinst_HEADERS = \
- osmocom/core/timer_compat.h \
osmocom/gsm/kasumi.h osmocom/gsm/gea.h
osmocom/core/bit%gen.h: osmocom/core/bitXXgen.h.tpl
diff --git a/include/osmocom/core/timer_compat.h b/include/osmocom/core/timer_compat.h
index 77d4ce0a..8fdd0a08 100644
--- a/include/osmocom/core/timer_compat.h
+++ b/include/osmocom/core/timer_compat.h
@@ -71,5 +71,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
+
+
/*! @} */