]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-event: split clock data allocation out of sd_event_add_time()
authorLennart Poettering <lennart@poettering.net>
Mon, 23 Nov 2020 10:40:24 +0000 (11:40 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 1 Dec 2020 14:10:50 +0000 (15:10 +0100)
Just some simple refactoring, that will make things easier for us later.
But it looks better this way even without the later function reuse.

src/libsystemd/sd-event/sd-event.c

index 720a98990fdf8f5ab3affc402dfd03b22adc718b..2213aafa8b5f4bc1112c1c406c3e0fdc518635aa 100644 (file)
@@ -1088,6 +1088,28 @@ static int time_exit_callback(sd_event_source *s, uint64_t usec, void *userdata)
         return sd_event_exit(sd_event_source_get_event(s), PTR_TO_INT(userdata));
 }
 
+static int setup_clock_data(sd_event *e, struct clock_data *d, clockid_t clock) {
+        int r;
+
+        assert(d);
+
+        if (d->fd < 0) {
+                r = event_setup_timer_fd(e, d, clock);
+                if (r < 0)
+                        return r;
+        }
+
+        r = prioq_ensure_allocated(&d->earliest, earliest_time_prioq_compare);
+        if (r < 0)
+                return r;
+
+        r = prioq_ensure_allocated(&d->latest, latest_time_prioq_compare);
+        if (r < 0)
+                return r;
+
+        return 0;
+}
+
 _public_ int sd_event_add_time(
                 sd_event *e,
                 sd_event_source **ret,
@@ -1121,20 +1143,10 @@ _public_ int sd_event_add_time(
         d = event_get_clock_data(e, type);
         assert(d);
 
-        r = prioq_ensure_allocated(&d->earliest, earliest_time_prioq_compare);
-        if (r < 0)
-                return r;
-
-        r = prioq_ensure_allocated(&d->latest, latest_time_prioq_compare);
+        r = setup_clock_data(e, d, clock);
         if (r < 0)
                 return r;
 
-        if (d->fd < 0) {
-                r = event_setup_timer_fd(e, d, clock);
-                if (r < 0)
-                        return r;
-        }
-
         s = source_new(e, !ret, type);
         if (!s)
                 return -ENOMEM;