ryantimwilson / rpms / systemd

Forked from rpms/systemd a month ago
Clone
592caf
From 97f599bf57fdaee688ae5750e9b2b2587e2b597a Mon Sep 17 00:00:00 2001
592caf
From: Lennart Poettering <lennart@poettering.net>
592caf
Date: Mon, 23 Nov 2020 17:49:27 +0100
592caf
Subject: [PATCH] sd-event: remove earliest_index/latest_index into common part
592caf
 of event source objects
592caf
592caf
So far we used these fields to organize the earliest/latest timer event
592caf
priority queue.  In a follow-up commit we want to introduce ratelimiting
592caf
to event sources, at which point we want any kind of event source to be
592caf
able to trigger time wakeups, and hence they all need to be included in
592caf
the earliest/latest prioqs.  Thus, in preparation let's make this
592caf
generic.
592caf
592caf
No change in behaviour, just some shifting around of struct members from
592caf
the type-specific to the generic part.
592caf
592caf
(cherry picked from commit f41315fceb5208c496145cda2d6c865a5458ce44)
592caf
592caf
Related: #1819868
592caf
---
592caf
 src/libsystemd/sd-event/sd-event.c | 25 +++++++++++++------------
592caf
 1 file changed, 13 insertions(+), 12 deletions(-)
592caf
592caf
diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c
592caf
index 739296abcf..34b42c298f 100644
592caf
--- a/src/libsystemd/sd-event/sd-event.c
592caf
+++ b/src/libsystemd/sd-event/sd-event.c
592caf
@@ -107,6 +107,9 @@ struct sd_event_source {
592caf
 
592caf
         LIST_FIELDS(sd_event_source, sources);
592caf
 
592caf
+        unsigned earliest_index;
592caf
+        unsigned latest_index;
592caf
+
592caf
         union {
592caf
                 struct {
592caf
                         sd_event_io_handler_t callback;
592caf
@@ -119,8 +122,6 @@ struct sd_event_source {
592caf
                 struct {
592caf
                         sd_event_time_handler_t callback;
592caf
                         usec_t next, accuracy;
592caf
-                        unsigned earliest_index;
592caf
-                        unsigned latest_index;
592caf
                 } time;
592caf
                 struct {
592caf
                         sd_event_signal_handler_t callback;
592caf
@@ -908,8 +909,8 @@ static void event_source_time_prioq_reshuffle(sd_event_source *s) {
592caf
         /* Called whenever the event source's timer ordering properties changed, i.e. time, accuracy,
592caf
          * pending, enable state. Makes sure the two prioq's are ordered properly again. */
592caf
         assert_se(d = event_get_clock_data(s->event, s->type));
592caf
-        prioq_reshuffle(d->earliest, s, &s->time.earliest_index);
592caf
-        prioq_reshuffle(d->latest, s, &s->time.latest_index);
592caf
+        prioq_reshuffle(d->earliest, s, &s->earliest_index);
592caf
+        prioq_reshuffle(d->latest, s, &s->latest_index);
592caf
         d->needs_rearm = true;
592caf
 }
592caf
 
592caf
@@ -920,9 +921,9 @@ static void event_source_time_prioq_remove(
592caf
         assert(s);
592caf
         assert(d);
592caf
 
592caf
-        prioq_remove(d->earliest, s, &s->time.earliest_index);
592caf
-        prioq_remove(d->latest, s, &s->time.latest_index);
592caf
-        s->time.earliest_index = s->time.latest_index = PRIOQ_IDX_NULL;
592caf
+        prioq_remove(d->earliest, s, &s->earliest_index);
592caf
+        prioq_remove(d->latest, s, &s->latest_index);
592caf
+        s->earliest_index = s->latest_index = PRIOQ_IDX_NULL;
592caf
         d->needs_rearm = true;
592caf
 }
592caf
 
592caf
@@ -1271,14 +1272,14 @@ static int event_source_time_prioq_put(
592caf
         assert(s);
592caf
         assert(d);
592caf
 
592caf
-        r = prioq_put(d->earliest, s, &s->time.earliest_index);
592caf
+        r = prioq_put(d->earliest, s, &s->earliest_index);
592caf
         if (r < 0)
592caf
                 return r;
592caf
 
592caf
-        r = prioq_put(d->latest, s, &s->time.latest_index);
592caf
+        r = prioq_put(d->latest, s, &s->latest_index);
592caf
         if (r < 0) {
592caf
-                assert_se(prioq_remove(d->earliest, s, &s->time.earliest_index) > 0);
592caf
-                s->time.earliest_index = PRIOQ_IDX_NULL;
592caf
+                assert_se(prioq_remove(d->earliest, s, &s->earliest_index) > 0);
592caf
+                s->earliest_index = PRIOQ_IDX_NULL;
592caf
                 return r;
592caf
         }
592caf
 
592caf
@@ -1329,7 +1330,7 @@ _public_ int sd_event_add_time(
592caf
         s->time.next = usec;
592caf
         s->time.accuracy = accuracy == 0 ? DEFAULT_ACCURACY_USEC : accuracy;
592caf
         s->time.callback = callback;
592caf
-        s->time.earliest_index = s->time.latest_index = PRIOQ_IDX_NULL;
592caf
+        s->earliest_index = s->latest_index = PRIOQ_IDX_NULL;
592caf
         s->userdata = userdata;
592caf
         s->enabled = SD_EVENT_ONESHOT;
592caf