teknoraver / rpms / systemd

Forked from rpms/systemd 3 months ago
Clone

Blame SOURCES/0549-sd-event-split-clock-data-allocation-out-of-sd_event.patch

b677e7
From 6cc0022115afbac9ac66c456b140601d90271687 Mon Sep 17 00:00:00 2001
b677e7
From: Lennart Poettering <lennart@poettering.net>
b677e7
Date: Mon, 23 Nov 2020 11:40:24 +0100
b677e7
Subject: [PATCH] sd-event: split clock data allocation out of
b677e7
 sd_event_add_time()
b677e7
b677e7
Just some simple refactoring, that will make things easier for us later.
b677e7
But it looks better this way even without the later function reuse.
b677e7
b677e7
(cherry picked from commit 41c63f36c3352af8bebf03b6181f5d866431d0af)
b677e7
b677e7
Related: #1819868
b677e7
---
b677e7
 src/libsystemd/sd-event/sd-event.c | 34 ++++++++++++++++++++----------
b677e7
 1 file changed, 23 insertions(+), 11 deletions(-)
b677e7
b677e7
diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c
b677e7
index 0f507f18d8..dc78dc7291 100644
b677e7
--- a/src/libsystemd/sd-event/sd-event.c
b677e7
+++ b/src/libsystemd/sd-event/sd-event.c
b677e7
@@ -1232,6 +1232,28 @@ static int time_exit_callback(sd_event_source *s, uint64_t usec, void *userdata)
b677e7
         return sd_event_exit(sd_event_source_get_event(s), PTR_TO_INT(userdata));
b677e7
 }
b677e7
 
b677e7
+static int setup_clock_data(sd_event *e, struct clock_data *d, clockid_t clock) {
b677e7
+        int r;
b677e7
+
b677e7
+        assert(d);
b677e7
+
b677e7
+        if (d->fd < 0) {
b677e7
+                r = event_setup_timer_fd(e, d, clock);
b677e7
+                if (r < 0)
b677e7
+                        return r;
b677e7
+        }
b677e7
+
b677e7
+        r = prioq_ensure_allocated(&d->earliest, earliest_time_prioq_compare);
b677e7
+        if (r < 0)
b677e7
+                return r;
b677e7
+
b677e7
+        r = prioq_ensure_allocated(&d->latest, latest_time_prioq_compare);
b677e7
+        if (r < 0)
b677e7
+                return r;
b677e7
+
b677e7
+        return 0;
b677e7
+}
b677e7
+
b677e7
 _public_ int sd_event_add_time(
b677e7
                 sd_event *e,
b677e7
                 sd_event_source **ret,
b677e7
@@ -1265,20 +1287,10 @@ _public_ int sd_event_add_time(
b677e7
         d = event_get_clock_data(e, type);
b677e7
         assert(d);
b677e7
 
b677e7
-        r = prioq_ensure_allocated(&d->earliest, earliest_time_prioq_compare);
b677e7
-        if (r < 0)
b677e7
-                return r;
b677e7
-
b677e7
-        r = prioq_ensure_allocated(&d->latest, latest_time_prioq_compare);
b677e7
+        r = setup_clock_data(e, d, clock);
b677e7
         if (r < 0)
b677e7
                 return r;
b677e7
 
b677e7
-        if (d->fd < 0) {
b677e7
-                r = event_setup_timer_fd(e, d, clock);
b677e7
-                if (r < 0)
b677e7
-                        return r;
b677e7
-        }
b677e7
-
b677e7
         s = source_new(e, !ret, type);
b677e7
         if (!s)
b677e7
                 return -ENOMEM;