diff options
author | Sven Eden <yamakuzure@gmx.net> | 2017-01-04 06:40:46 +0100 |
---|---|---|
committer | Sven Eden <yamakuzure@gmx.net> | 2017-03-14 10:18:46 +0100 |
commit | 21ecddbbb2c9e06d080b2526a870898a8b90f52a (patch) | |
tree | 458198518cde60db77fc2acc0191a082e37dea33 /src/basic/time-util.c | |
parent | 54ce5835917e44761df5c7071fa9111f5be4008a (diff) |
Prep v225: Applying various fixes and changes to src/basic that got lost during git am transfer.
Diffstat (limited to 'src/basic/time-util.c')
-rw-r--r-- | src/basic/time-util.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/basic/time-util.c b/src/basic/time-util.c index e849ccc57..de9263bf7 100644 --- a/src/basic/time-util.c +++ b/src/basic/time-util.c @@ -91,6 +91,32 @@ dual_timestamp* dual_timestamp_from_monotonic(dual_timestamp *ts, usec_t u) { } #endif // 0 +dual_timestamp* dual_timestamp_from_boottime_or_monotonic(dual_timestamp *ts, usec_t u) { + int64_t delta; + + if (u == USEC_INFINITY) { + ts->realtime = ts->monotonic = USEC_INFINITY; + return ts; + } + ts->realtime = now(CLOCK_REALTIME); + ts->monotonic = now(CLOCK_MONOTONIC); + + 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; + + return ts; +} + + usec_t timespec_load(const struct timespec *ts) { assert(ts); |