teknoraver / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone

Blame SOURCES/0556-sd-event-remove-earliest_index-latest_index-into-com.patch

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