summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2014-08-14 00:22:27 +0200
committerTom Gundersen <teg@jklm.no>2014-08-14 01:29:51 +0200
commit212bbb1798e5746a669dfba4a1732a4eabe4f2d8 (patch)
tree59ca18cec9b0de6c522e0e426d9b69a28156f676
parente92da1e5d0a3b38804e173af136ec7a076c7757e (diff)
sd-event: do not arm timers unnecessarily
Rather than recalculating the next timeout on every loop, we only do it when something changed.
-rw-r--r--src/libsystemd/sd-event/sd-event.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c
index bf6f01cfad..d6549148bb 100644
--- a/src/libsystemd/sd-event/sd-event.c
+++ b/src/libsystemd/sd-event/sd-event.c
@@ -131,6 +131,8 @@ struct clock_data {
Prioq *earliest;
Prioq *latest;
usec_t next;
+
+ bool needs_rearm:1;
};
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->latest, s, &s->time.latest_index);
+ d->needs_rearm = true;
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->latest, s, &s->time.latest_index);
+ d->needs_rearm = true;
}
return 0;
@@ -898,6 +902,8 @@ _public_ int sd_event_add_time(
if (r < 0)
goto fail;
+ d->needs_rearm = true;
+
if (ret)
*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->latest, s, &s->time.latest_index);
+ d->needs_rearm = true;
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->latest, s, &s->time.latest_index);
+ d->needs_rearm = true;
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->latest, s, &s->time.latest_index);
+ d->needs_rearm = true;
return 0;
}
@@ -1582,6 +1591,7 @@ _public_ int sd_event_source_set_time_accuracy(sd_event_source *s, uint64_t usec
assert(d);
prioq_reshuffle(d->latest, s, &s->time.latest_index);
+ d->needs_rearm = true;
return 0;
}
@@ -1745,6 +1755,11 @@ static int event_arm_timer(
assert(e);
assert(d);
+ if (_likely_(!d->needs_rearm))
+ return 0;
+ else
+ d->needs_rearm = false;
+
a = prioq_peek(d->earliest);
if (!a || a->enabled == SD_EVENT_OFF) {