static void test_sd_event_now(void) { _cleanup_(sd_event_unrefp) sd_event *e = NULL; uint64_t event_now; assert_se(sd_event_new(&e) >= 0); assert_se(sd_event_now(e, CLOCK_MONOTONIC, &event_now) > 0); assert_se(sd_event_now(e, CLOCK_REALTIME, &event_now) > 0); assert_se(sd_event_now(e, CLOCK_REALTIME_ALARM, &event_now) > 0); if (clock_boottime_supported()) { assert_se(sd_event_now(e, CLOCK_BOOTTIME, &event_now) > 0); assert_se(sd_event_now(e, CLOCK_BOOTTIME_ALARM, &event_now) > 0); } assert_se(sd_event_now(e, -1, &event_now) == -EOPNOTSUPP); assert_se(sd_event_now(e, 900 /* arbitrary big number */, &event_now) == -EOPNOTSUPP); assert_se(sd_event_run(e, 0) == 0); assert_se(sd_event_now(e, CLOCK_MONOTONIC, &event_now) == 0); assert_se(sd_event_now(e, CLOCK_REALTIME, &event_now) == 0); assert_se(sd_event_now(e, CLOCK_REALTIME_ALARM, &event_now) == 0); if (clock_boottime_supported()) { assert_se(sd_event_now(e, CLOCK_BOOTTIME, &event_now) == 0); assert_se(sd_event_now(e, CLOCK_BOOTTIME_ALARM, &event_now) == 0); } assert_se(sd_event_now(e, -1, &event_now) == -EOPNOTSUPP); assert_se(sd_event_now(e, 900 /* arbitrary big number */, &event_now) == -EOPNOTSUPP); }
triple_timestamp* triple_timestamp_get(triple_timestamp *ts) { assert(ts); ts->realtime = now(CLOCK_REALTIME); ts->monotonic = now(CLOCK_MONOTONIC); ts->boottime = clock_boottime_supported() ? now(CLOCK_BOOTTIME) : USEC_INFINITY; return ts; }
triple_timestamp* triple_timestamp_from_realtime(triple_timestamp *ts, usec_t u) { int64_t delta; assert(ts); if (u == USEC_INFINITY || u <= 0) { ts->realtime = ts->monotonic = ts->boottime = u; return ts; } ts->realtime = u; delta = (int64_t) now(CLOCK_REALTIME) - (int64_t) u; ts->monotonic = usec_sub(now(CLOCK_MONOTONIC), delta); ts->boottime = clock_boottime_supported() ? usec_sub(now(CLOCK_BOOTTIME), delta) : USEC_INFINITY; return ts; }