sd-event: do not arm timers unnecessarily
Rather than recalculating the next timeout on every loop, we only do it when something changed.
This commit is contained in:
parent
e92da1e5d0
commit
212bbb1798
|
@ -131,6 +131,8 @@ struct clock_data {
|
||||||
Prioq *earliest;
|
Prioq *earliest;
|
||||||
Prioq *latest;
|
Prioq *latest;
|
||||||
usec_t next;
|
usec_t next;
|
||||||
|
|
||||||
|
bool needs_rearm:1;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sd_event {
|
struct sd_event {
|
||||||
|
@ -616,6 +618,7 @@ static void source_disconnect(sd_event_source *s) {
|
||||||
|
|
||||||
prioq_remove(d->earliest, s, &s->time.earliest_index);
|
prioq_remove(d->earliest, s, &s->time.earliest_index);
|
||||||
prioq_remove(d->latest, s, &s->time.latest_index);
|
prioq_remove(d->latest, s, &s->time.latest_index);
|
||||||
|
d->needs_rearm = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -715,6 +718,7 @@ static int source_set_pending(sd_event_source *s, bool b) {
|
||||||
|
|
||||||
prioq_reshuffle(d->earliest, s, &s->time.earliest_index);
|
prioq_reshuffle(d->earliest, s, &s->time.earliest_index);
|
||||||
prioq_reshuffle(d->latest, s, &s->time.latest_index);
|
prioq_reshuffle(d->latest, s, &s->time.latest_index);
|
||||||
|
d->needs_rearm = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -898,6 +902,8 @@ _public_ int sd_event_add_time(
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
|
d->needs_rearm = true;
|
||||||
|
|
||||||
if (ret)
|
if (ret)
|
||||||
*ret = s;
|
*ret = s;
|
||||||
|
|
||||||
|
@ -1408,6 +1414,7 @@ _public_ int sd_event_source_set_enabled(sd_event_source *s, int m) {
|
||||||
|
|
||||||
prioq_reshuffle(d->earliest, s, &s->time.earliest_index);
|
prioq_reshuffle(d->earliest, s, &s->time.earliest_index);
|
||||||
prioq_reshuffle(d->latest, s, &s->time.latest_index);
|
prioq_reshuffle(d->latest, s, &s->time.latest_index);
|
||||||
|
d->needs_rearm = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1471,6 +1478,7 @@ _public_ int sd_event_source_set_enabled(sd_event_source *s, int m) {
|
||||||
|
|
||||||
prioq_reshuffle(d->earliest, s, &s->time.earliest_index);
|
prioq_reshuffle(d->earliest, s, &s->time.earliest_index);
|
||||||
prioq_reshuffle(d->latest, s, &s->time.latest_index);
|
prioq_reshuffle(d->latest, s, &s->time.latest_index);
|
||||||
|
d->needs_rearm = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1548,6 +1556,7 @@ _public_ int sd_event_source_set_time(sd_event_source *s, uint64_t usec) {
|
||||||
|
|
||||||
prioq_reshuffle(d->earliest, s, &s->time.earliest_index);
|
prioq_reshuffle(d->earliest, s, &s->time.earliest_index);
|
||||||
prioq_reshuffle(d->latest, s, &s->time.latest_index);
|
prioq_reshuffle(d->latest, s, &s->time.latest_index);
|
||||||
|
d->needs_rearm = true;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1582,6 +1591,7 @@ _public_ int sd_event_source_set_time_accuracy(sd_event_source *s, uint64_t usec
|
||||||
assert(d);
|
assert(d);
|
||||||
|
|
||||||
prioq_reshuffle(d->latest, s, &s->time.latest_index);
|
prioq_reshuffle(d->latest, s, &s->time.latest_index);
|
||||||
|
d->needs_rearm = true;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1745,6 +1755,11 @@ static int event_arm_timer(
|
||||||
assert(e);
|
assert(e);
|
||||||
assert(d);
|
assert(d);
|
||||||
|
|
||||||
|
if (_likely_(!d->needs_rearm))
|
||||||
|
return 0;
|
||||||
|
else
|
||||||
|
d->needs_rearm = false;
|
||||||
|
|
||||||
a = prioq_peek(d->earliest);
|
a = prioq_peek(d->earliest);
|
||||||
if (!a || a->enabled == SD_EVENT_OFF) {
|
if (!a || a->enabled == SD_EVENT_OFF) {
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue