summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-01-08 01:27:39 +0100
committerLennart Poettering <lennart@poettering.net>2013-01-08 01:27:39 +0100
commitcae0c5e042c04b33b93a6a9af355f7304f75a45c (patch)
tree29019a6faf9e84e50e769a5b2e20f587075e60d0 /src/shared
parent6ee667aeeb284b652e256ad1d792b0fb6c28faba (diff)
core: properly initialize kernel timestamp
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/time-util.c26
-rw-r--r--src/shared/time-util.h1
2 files changed, 27 insertions, 0 deletions
diff --git a/src/shared/time-util.c b/src/shared/time-util.c
index 13d57ba5cd..4fd8f08984 100644
--- a/src/shared/time-util.c
+++ b/src/shared/time-util.c
@@ -46,6 +46,11 @@ dual_timestamp* dual_timestamp_from_realtime(dual_timestamp *ts, usec_t u) {
int64_t delta;
assert(ts);
+ if (u == (usec_t) -1) {
+ ts->realtime = ts->monotonic = (usec_t) -1;
+ return ts;
+ }
+
ts->realtime = u;
if (u == 0)
@@ -64,6 +69,27 @@ dual_timestamp* dual_timestamp_from_realtime(dual_timestamp *ts, usec_t u) {
return ts;
}
+dual_timestamp* dual_timestamp_from_monotonic(dual_timestamp *ts, usec_t u) {
+ int64_t delta;
+ assert(ts);
+
+ if (u == (usec_t) -1) {
+ ts->realtime = ts->monotonic = (usec_t) -1;
+ return ts;
+ }
+
+ 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;
+
+ return ts;
+}
+
usec_t timespec_load(const struct timespec *ts) {
assert(ts);
diff --git a/src/shared/time-util.h b/src/shared/time-util.h
index 7194875ec2..ec263c1a19 100644
--- a/src/shared/time-util.h
+++ b/src/shared/time-util.h
@@ -61,6 +61,7 @@ usec_t now(clockid_t clock);
dual_timestamp* dual_timestamp_get(dual_timestamp *ts);
dual_timestamp* dual_timestamp_from_realtime(dual_timestamp *ts, usec_t u);
+dual_timestamp* dual_timestamp_from_monotonic(dual_timestamp *ts, usec_t u);
#define dual_timestamp_is_set(ts) ((ts)->realtime > 0)