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.
This commit is contained in:
Alexander Kuleshov
2016-02-09 01:15:17 +06:00
parent ef9fde5378
commit 5d634ca8ce
2 changed files with 15 additions and 22 deletions
+11
View File
@@ -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;
}