dryang / rpms / systemd

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