summaryrefslogtreecommitdiff
path: root/src/basic/time-util.h
diff options
context:
space:
mode:
authorAlexander Kuleshov <kuleshovmail@gmail.com>2016-02-05 00:02:39 +0600
committerAlexander Kuleshov <kuleshovmail@gmail.com>2016-02-09 01:15:17 +0600
commit5d634ca8cefb3d738d9efa70dfcc2f67d85d99e9 (patch)
treeca648a970230dd03b23c976e055daa0a76c3efac /src/basic/time-util.h
parentef9fde5378c0b2614991f9e3c4ac525cc07736a8 (diff)
time-util: introduce usec_sub()
The dual_timestamp_from_realtime(), dual_timestamp_from_monotonic() and dual_timestamp_from_boottime_or_monotonic() shares the same code for comparison given ts with delta. Let's move it to the separate inline function to prevent code duplication.
Diffstat (limited to 'src/basic/time-util.h')
-rw-r--r--src/basic/time-util.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/basic/time-util.h b/src/basic/time-util.h
index 9c7758a959..87440faeee 100644
--- a/src/basic/time-util.h
+++ b/src/basic/time-util.h
@@ -140,3 +140,14 @@ static inline usec_t usec_add(usec_t a, usec_t b) {
return c;
}
+
+static inline usec_t usec_sub(usec_t timestamp, int64_t delta) {
+ if (delta < 0)
+ timestamp = usec_add(timestamp, (usec_t) (-delta));
+ else if (timestamp > (usec_t) delta)
+ timestamp -= delta;
+ else
+ timestamp = 0;
+
+ return timestamp;
+}