]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
time-util: introduce triple_timestamp_from_boottime()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 4 Sep 2023 17:14:01 +0000 (02:14 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 5 Sep 2023 17:02:21 +0000 (02:02 +0900)
src/basic/time-util.c
src/basic/time-util.h

index 1db630003a40323065262ae2b6d4007128daffc4..a6790d207ce7771f3957f555386e9e508c88b6a5 100644 (file)
@@ -156,6 +156,25 @@ triple_timestamp* triple_timestamp_from_realtime(triple_timestamp *ts, usec_t u)
         return ts;
 }
 
+triple_timestamp* triple_timestamp_from_boottime(triple_timestamp *ts, usec_t u) {
+        usec_t nowb;
+
+        assert(ts);
+
+        if (u == USEC_INFINITY) {
+                ts->realtime = ts->monotonic = ts->boottime = u;
+                return ts;
+        }
+
+        nowb = now(CLOCK_BOOTTIME);
+
+        ts->boottime = u;
+        ts->monotonic = map_clock_usec_internal(u, nowb, now(CLOCK_MONOTONIC));
+        ts->realtime = map_clock_usec_internal(u, nowb, now(CLOCK_REALTIME));
+
+        return ts;
+}
+
 dual_timestamp* dual_timestamp_from_monotonic(dual_timestamp *ts, usec_t u) {
         assert(ts);
 
index 57283d31a726ae2cf59177fca7c2f3a8c197cbac..b648a3b59ea1defbe8e87bbe954656be3059d2d7 100644 (file)
@@ -86,6 +86,7 @@ dual_timestamp* dual_timestamp_from_boottime(dual_timestamp *ts, usec_t u);
 
 triple_timestamp* triple_timestamp_get(triple_timestamp *ts);
 triple_timestamp* triple_timestamp_from_realtime(triple_timestamp *ts, usec_t u);
+triple_timestamp* triple_timestamp_from_boottime(triple_timestamp *ts, usec_t u);
 
 #define DUAL_TIMESTAMP_HAS_CLOCK(clock)                               \
         IN_SET(clock, CLOCK_REALTIME, CLOCK_REALTIME_ALARM, CLOCK_MONOTONIC)