sd-event: port over to new triple timestamp logic
This commit is contained in:
parent
fe624c4c07
commit
e475d10c1b
|
@ -216,8 +216,7 @@ struct sd_event {
|
||||||
pid_t original_pid;
|
pid_t original_pid;
|
||||||
|
|
||||||
unsigned iteration;
|
unsigned iteration;
|
||||||
dual_timestamp timestamp;
|
triple_timestamp timestamp;
|
||||||
usec_t timestamp_boottime;
|
|
||||||
int state;
|
int state;
|
||||||
|
|
||||||
bool exit_requested:1;
|
bool exit_requested:1;
|
||||||
|
@ -1072,16 +1071,16 @@ _public_ int sd_event_add_time(
|
||||||
assert_return(e->state != SD_EVENT_FINISHED, -ESTALE);
|
assert_return(e->state != SD_EVENT_FINISHED, -ESTALE);
|
||||||
assert_return(!event_pid_changed(e), -ECHILD);
|
assert_return(!event_pid_changed(e), -ECHILD);
|
||||||
|
|
||||||
if (IN_SET(clock, CLOCK_BOOTTIME, CLOCK_BOOTTIME_ALARM) &&
|
if (!clock_supported(clock)) /* Checks whether the kernel supports the clock */
|
||||||
!clock_boottime_supported())
|
return -EOPNOTSUPP;
|
||||||
|
|
||||||
|
type = clock_to_event_source_type(clock); /* checks whether sd-event supports this clock */
|
||||||
|
if (type < 0)
|
||||||
return -EOPNOTSUPP;
|
return -EOPNOTSUPP;
|
||||||
|
|
||||||
if (!callback)
|
if (!callback)
|
||||||
callback = time_exit_callback;
|
callback = time_exit_callback;
|
||||||
|
|
||||||
type = clock_to_event_source_type(clock);
|
|
||||||
assert_return(type >= 0, -EOPNOTSUPP);
|
|
||||||
|
|
||||||
d = event_get_clock_data(e, type);
|
d = event_get_clock_data(e, type);
|
||||||
assert(d);
|
assert(d);
|
||||||
|
|
||||||
|
@ -2530,9 +2529,7 @@ _public_ int sd_event_wait(sd_event *e, uint64_t timeout) {
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
dual_timestamp_get(&e->timestamp);
|
triple_timestamp_get(&e->timestamp);
|
||||||
if (clock_boottime_supported())
|
|
||||||
e->timestamp_boottime = now(CLOCK_BOOTTIME);
|
|
||||||
|
|
||||||
for (i = 0; i < m; i++) {
|
for (i = 0; i < m; i++) {
|
||||||
|
|
||||||
|
@ -2573,7 +2570,7 @@ _public_ int sd_event_wait(sd_event *e, uint64_t timeout) {
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
goto finish;
|
goto finish;
|
||||||
|
|
||||||
r = process_timer(e, e->timestamp_boottime, &e->boottime);
|
r = process_timer(e, e->timestamp.boottime, &e->boottime);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
goto finish;
|
goto finish;
|
||||||
|
|
||||||
|
@ -2585,7 +2582,7 @@ _public_ int sd_event_wait(sd_event *e, uint64_t timeout) {
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
goto finish;
|
goto finish;
|
||||||
|
|
||||||
r = process_timer(e, e->timestamp_boottime, &e->boottime_alarm);
|
r = process_timer(e, e->timestamp.boottime, &e->boottime_alarm);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
goto finish;
|
goto finish;
|
||||||
|
|
||||||
|
@ -2759,43 +2756,24 @@ _public_ int sd_event_now(sd_event *e, clockid_t clock, uint64_t *usec) {
|
||||||
assert_return(e, -EINVAL);
|
assert_return(e, -EINVAL);
|
||||||
assert_return(usec, -EINVAL);
|
assert_return(usec, -EINVAL);
|
||||||
assert_return(!event_pid_changed(e), -ECHILD);
|
assert_return(!event_pid_changed(e), -ECHILD);
|
||||||
assert_return(IN_SET(clock,
|
|
||||||
CLOCK_REALTIME,
|
|
||||||
CLOCK_REALTIME_ALARM,
|
|
||||||
CLOCK_MONOTONIC,
|
|
||||||
CLOCK_BOOTTIME,
|
|
||||||
CLOCK_BOOTTIME_ALARM), -EOPNOTSUPP);
|
|
||||||
|
|
||||||
|
if (!TRIPLE_TIMESTAMP_HAS_CLOCK(clock))
|
||||||
|
return -EOPNOTSUPP;
|
||||||
|
|
||||||
|
/* Generate a clean error in case CLOCK_BOOTTIME is not available. Note that don't use clock_supported() here,
|
||||||
|
* for a reason: there are systems where CLOCK_BOOTTIME is supported, but CLOCK_BOOTTIME_ALARM is not, but for
|
||||||
|
* the purpose of getting the time this doesn't matter. */
|
||||||
if (IN_SET(clock, CLOCK_BOOTTIME, CLOCK_BOOTTIME_ALARM) && !clock_boottime_supported())
|
if (IN_SET(clock, CLOCK_BOOTTIME, CLOCK_BOOTTIME_ALARM) && !clock_boottime_supported())
|
||||||
return -EOPNOTSUPP;
|
return -EOPNOTSUPP;
|
||||||
|
|
||||||
if (!dual_timestamp_is_set(&e->timestamp)) {
|
if (!triple_timestamp_is_set(&e->timestamp)) {
|
||||||
/* Implicitly fall back to now() if we never ran
|
/* Implicitly fall back to now() if we never ran
|
||||||
* before and thus have no cached time. */
|
* before and thus have no cached time. */
|
||||||
*usec = now(clock);
|
*usec = now(clock);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (clock) {
|
*usec = triple_timestamp_by_clock(&e->timestamp, clock);
|
||||||
|
|
||||||
case CLOCK_REALTIME:
|
|
||||||
case CLOCK_REALTIME_ALARM:
|
|
||||||
*usec = e->timestamp.realtime;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CLOCK_MONOTONIC:
|
|
||||||
*usec = e->timestamp.monotonic;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CLOCK_BOOTTIME:
|
|
||||||
case CLOCK_BOOTTIME_ALARM:
|
|
||||||
*usec = e->timestamp_boottime;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
assert_not_reached("Unknown clock?");
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue