mirror of
https://github.com/systemd/systemd.git
synced 2024-11-01 09:21:26 +03:00
core: properly initialize kernel timestamp
This commit is contained in:
parent
6ee667aeeb
commit
cae0c5e042
@ -301,6 +301,7 @@ int manager_new(SystemdRunningAs running_as, Manager **_m) {
|
||||
return -ENOMEM;
|
||||
|
||||
dual_timestamp_get(&m->userspace_timestamp);
|
||||
dual_timestamp_from_monotonic(&m->kernel_timestamp, 0);
|
||||
|
||||
m->running_as = running_as;
|
||||
m->name_data_slot = m->conn_data_slot = m->subscribed_data_slot = -1;
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user