summaryrefslogtreecommitdiff
path: root/src/basic/time-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2016-02-09 00:23:47 +0100
committerLennart Poettering <lennart@poettering.net>2016-02-09 00:23:47 +0100
commit70b65964d7ef03621f5d4abd23150c1b121989b4 (patch)
tree023e8a63f92c50102469cece69f517f5325324ac /src/basic/time-util.c
parent41c24512cc399ca01f70ec9de6b17273446b170a (diff)
parent5d634ca8cefb3d738d9efa70dfcc2f67d85d99e9 (diff)
Merge pull request #2542 from 0xAX/get_ts_delta
time-util: cleanups
Diffstat (limited to 'src/basic/time-util.c')
-rw-r--r--src/basic/time-util.c26
1 files changed, 4 insertions, 22 deletions
diff --git a/src/basic/time-util.c b/src/basic/time-util.c
index 8c42df9b9f..3f3863910b 100644
--- a/src/basic/time-util.c
+++ b/src/basic/time-util.c
@@ -79,12 +79,7 @@ dual_timestamp* dual_timestamp_from_realtime(dual_timestamp *ts, usec_t u) {
ts->realtime = u;
delta = (int64_t) now(CLOCK_REALTIME) - (int64_t) u;
- ts->monotonic = now(CLOCK_MONOTONIC);
-
- if ((int64_t) ts->monotonic > delta)
- ts->monotonic -= delta;
- else
- ts->monotonic = 0;
+ ts->monotonic = usec_sub(now(CLOCK_MONOTONIC), delta);
return ts;
}
@@ -100,12 +95,7 @@ dual_timestamp* dual_timestamp_from_monotonic(dual_timestamp *ts, usec_t u) {
ts->monotonic = u;
delta = (int64_t) now(CLOCK_MONOTONIC) - (int64_t) u;
-
- ts->realtime = now(CLOCK_REALTIME);
- if ((int64_t) ts->realtime > delta)
- ts->realtime -= delta;
- else
- ts->realtime = 0;
+ ts->realtime = usec_sub(now(CLOCK_REALTIME), delta);
return ts;
}
@@ -120,16 +110,8 @@ dual_timestamp* dual_timestamp_from_boottime_or_monotonic(dual_timestamp *ts, us
dual_timestamp_get(ts);
delta = (int64_t) now(clock_boottime_or_monotonic()) - (int64_t) u;
-
- if ((int64_t) ts->realtime > delta)
- ts->realtime -= delta;
- else
- ts->realtime = 0;
-
- if ((int64_t) ts->monotonic > delta)
- ts->monotonic -= delta;
- else
- ts->monotonic = 0;
+ ts->realtime = usec_sub(ts->realtime, delta);
+ ts->monotonic = usec_sub(ts->monotonic, delta);
return ts;
}