5c5d01915a
Porting 851/909/910/913/919/920/922/923/924/925/926/927 patches to debian, other patches are confirmed in debian version. Story: 2009221 Task: 43416 Signed-off-by: Yue Tao <yue.tao@windriver.com> Change-Id: I5af677c90342bae7c30991bf465e0db79c71667d
121 lines
3.6 KiB
Diff
121 lines
3.6 KiB
Diff
From dad1d000b493f98f4f5eaf4bfa34c8617f41970f Mon Sep 17 00:00:00 2001
|
|
From: Lennart Poettering <lennart@poettering.net>
|
|
Date: Mon, 23 Nov 2020 15:25:35 +0100
|
|
Subject: [PATCH 10/20] sd-event: split out code to add/remove timer event
|
|
sources to earliest/latest prioq
|
|
|
|
Just some refactoring that makes code prettier, and will come handy
|
|
later, because we can reuse these functions at more places.
|
|
|
|
(cherry picked from commit 1e45e3fecc303e7ae9946220c742f69675e99c34)
|
|
|
|
Related: #1819868
|
|
|
|
[commit 88b2618e4de850060a1c5c22b049e6de0578fbb5 from
|
|
https://github.com/systemd-rhel/rhel-8/]
|
|
|
|
Signed-off-by: Li Zhou <li.zhou@windriver.com>
|
|
---
|
|
src/libsystemd/sd-event/sd-event.c | 57 +++++++++++++++++++++---------
|
|
1 file changed, 41 insertions(+), 16 deletions(-)
|
|
|
|
diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c
|
|
index 8e6536f..e0e0eaa 100644
|
|
--- a/src/libsystemd/sd-event/sd-event.c
|
|
+++ b/src/libsystemd/sd-event/sd-event.c
|
|
@@ -723,6 +723,19 @@ static void event_source_time_prioq_resh
|
|
d->needs_rearm = true;
|
|
}
|
|
|
|
+static void event_source_time_prioq_remove(
|
|
+ sd_event_source *s,
|
|
+ struct clock_data *d) {
|
|
+
|
|
+ assert(s);
|
|
+ assert(d);
|
|
+
|
|
+ prioq_remove(d->earliest, s, &s->time.earliest_index);
|
|
+ prioq_remove(d->latest, s, &s->time.latest_index);
|
|
+ s->time.earliest_index = s->time.latest_index = PRIOQ_IDX_NULL;
|
|
+ d->needs_rearm = true;
|
|
+}
|
|
+
|
|
static void source_disconnect(sd_event_source *s) {
|
|
sd_event *event;
|
|
|
|
@@ -747,13 +760,8 @@ static void source_disconnect(sd_event_s
|
|
case SOURCE_TIME_REALTIME_ALARM:
|
|
case SOURCE_TIME_BOOTTIME_ALARM: {
|
|
struct clock_data *d;
|
|
-
|
|
- d = event_get_clock_data(s->event, s->type);
|
|
- assert(d);
|
|
-
|
|
- prioq_remove(d->earliest, s, &s->time.earliest_index);
|
|
- prioq_remove(d->latest, s, &s->time.latest_index);
|
|
- d->needs_rearm = true;
|
|
+ assert_se(d = event_get_clock_data(s->event, s->type));
|
|
+ event_source_time_prioq_remove(s, d);
|
|
break;
|
|
}
|
|
|
|
@@ -1110,6 +1118,30 @@ static int setup_clock_data(sd_event *e,
|
|
return 0;
|
|
}
|
|
|
|
+static int event_source_time_prioq_put(
|
|
+ sd_event_source *s,
|
|
+ struct clock_data *d) {
|
|
+
|
|
+ int r;
|
|
+
|
|
+ assert(s);
|
|
+ assert(d);
|
|
+
|
|
+ r = prioq_put(d->earliest, s, &s->time.earliest_index);
|
|
+ if (r < 0)
|
|
+ return r;
|
|
+
|
|
+ r = prioq_put(d->latest, s, &s->time.latest_index);
|
|
+ if (r < 0) {
|
|
+ assert_se(prioq_remove(d->earliest, s, &s->time.earliest_index) > 0);
|
|
+ s->time.earliest_index = PRIOQ_IDX_NULL;
|
|
+ return r;
|
|
+ }
|
|
+
|
|
+ d->needs_rearm = true;
|
|
+ return 0;
|
|
+}
|
|
+
|
|
_public_ int sd_event_add_time(
|
|
sd_event *e,
|
|
sd_event_source **ret,
|
|
@@ -1140,8 +1172,7 @@ _public_ int sd_event_add_time(
|
|
if (!callback)
|
|
callback = time_exit_callback;
|
|
|
|
- d = event_get_clock_data(e, type);
|
|
- assert(d);
|
|
+ assert_se(d = event_get_clock_data(e, type));
|
|
|
|
r = setup_clock_data(e, d, clock);
|
|
if (r < 0)
|
|
@@ -1158,13 +1189,7 @@ _public_ int sd_event_add_time(
|
|
s->userdata = userdata;
|
|
s->enabled = SD_EVENT_ONESHOT;
|
|
|
|
- d->needs_rearm = true;
|
|
-
|
|
- r = prioq_put(d->earliest, s, &s->time.earliest_index);
|
|
- if (r < 0)
|
|
- return r;
|
|
-
|
|
- r = prioq_put(d->latest, s, &s->time.latest_index);
|
|
+ r = event_source_time_prioq_put(s, d);
|
|
if (r < 0)
|
|
return r;
|
|
|
|
--
|
|
2.17.1
|
|
|