summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@diac24.net>2019-07-17 15:26:00 +0200
committerDavid Lamparter <equinox@diac24.net>2019-08-30 19:00:45 +0200
commit8defc5be5204275e2314f56229fa2be5ae14c699 (patch)
tree38c9232fa9c321677faad345dcdc55a9d8302620
parent5c52c06c5c713e16d3c317a315c49b87179b1964 (diff)
lib: add monotime_to_realtime()
Signed-off-by: David Lamparter <equinox@diac24.net>
-rw-r--r--lib/monotime.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/monotime.h b/lib/monotime.h
index ca27c45dc6..e246f177de 100644
--- a/lib/monotime.h
+++ b/lib/monotime.h
@@ -84,6 +84,20 @@ static inline int64_t monotime_until(const struct timeval *ref,
return (int64_t)tv.tv_sec * 1000000LL + tv.tv_usec;
}
+static inline time_t monotime_to_realtime(const struct timeval *mono,
+ struct timeval *realout)
+{
+ struct timeval delta, real;
+
+ monotime_since(mono, &delta);
+ gettimeofday(&real, NULL);
+
+ timersub(&real, &delta, &real);
+ if (realout)
+ *realout = real;
+ return real.tv_sec;
+}
+
/* Char buffer size for time-to-string api */
#define MONOTIME_STRLEN 32