446ea3
From eaab8d57d9db0d98d7e618ba634983c34cdb9c06 Mon Sep 17 00:00:00 2001
446ea3
From: Yu Watanabe <watanabe.yu+github@gmail.com>
446ea3
Date: Tue, 15 Jun 2021 00:51:33 +0900
446ea3
Subject: [PATCH] sd-event: use CMP() macro
446ea3
446ea3
(cherry picked from commit 06e131477d82b83c5d516e66d6e413affd7c774a)
446ea3
446ea3
Related: #1984406
446ea3
---
446ea3
 src/libsystemd/sd-event/sd-event.c | 37 ++++++++++++++----------------
446ea3
 1 file changed, 17 insertions(+), 20 deletions(-)
446ea3
446ea3
diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c
446ea3
index 2b0b76aa1c..6a20b658e4 100644
446ea3
--- a/src/libsystemd/sd-event/sd-event.c
446ea3
+++ b/src/libsystemd/sd-event/sd-event.c
446ea3
@@ -358,10 +358,9 @@ static int pending_prioq_compare(const void *a, const void *b) {
446ea3
         assert(y->pending);
446ea3
 
446ea3
         /* Enabled ones first */
446ea3
-        if (x->enabled != SD_EVENT_OFF && y->enabled == SD_EVENT_OFF)
446ea3
-                return -1;
446ea3
-        if (x->enabled == SD_EVENT_OFF && y->enabled != SD_EVENT_OFF)
446ea3
-                return 1;
446ea3
+        r = CMP(x->enabled == SD_EVENT_OFF, y->enabled == SD_EVENT_OFF);
446ea3
+        if (r != 0)
446ea3
+                return r;
446ea3
 
446ea3
         /* Non rate-limited ones first. */
446ea3
         r = CMP(!!x->ratelimited, !!y->ratelimited);
446ea3
@@ -385,10 +384,9 @@ static int prepare_prioq_compare(const void *a, const void *b) {
446ea3
         assert(y->prepare);
446ea3
 
446ea3
         /* Enabled ones first */
446ea3
-        if (x->enabled != SD_EVENT_OFF && y->enabled == SD_EVENT_OFF)
446ea3
-                return -1;
446ea3
-        if (x->enabled == SD_EVENT_OFF && y->enabled != SD_EVENT_OFF)
446ea3
-                return 1;
446ea3
+        r = CMP(x->enabled == SD_EVENT_OFF, y->enabled == SD_EVENT_OFF);
446ea3
+        if (r != 0)
446ea3
+                return r;
446ea3
 
446ea3
         /* Non rate-limited ones first. */
446ea3
         r = CMP(!!x->ratelimited, !!y->ratelimited);
446ea3
@@ -455,18 +453,17 @@ static bool event_source_timer_candidate(const sd_event_source *s) {
446ea3
 
446ea3
 static int time_prioq_compare(const void *a, const void *b, usec_t (*time_func)(const sd_event_source *s)) {
446ea3
         const sd_event_source *x = a, *y = b;
446ea3
+        int r;
446ea3
 
446ea3
         /* Enabled ones first */
446ea3
-        if (x->enabled != SD_EVENT_OFF && y->enabled == SD_EVENT_OFF)
446ea3
-                return -1;
446ea3
-        if (x->enabled == SD_EVENT_OFF && y->enabled != SD_EVENT_OFF)
446ea3
-                return 1;
446ea3
+        r = CMP(x->enabled == SD_EVENT_OFF, y->enabled == SD_EVENT_OFF);
446ea3
+        if (r != 0)
446ea3
+                return r;
446ea3
 
446ea3
         /* Order "non-pending OR ratelimited" before "pending AND not-ratelimited" */
446ea3
-        if (event_source_timer_candidate(x) && !event_source_timer_candidate(y))
446ea3
-                return -1;
446ea3
-        if (!event_source_timer_candidate(x) && event_source_timer_candidate(y))
446ea3
-                return 1;
446ea3
+        r = CMP(!event_source_timer_candidate(x), !event_source_timer_candidate(y));
446ea3
+        if (r != 0)
446ea3
+                return r;
446ea3
 
446ea3
         /* Order by time */
446ea3
         return CMP(time_func(x), time_func(y));
446ea3
@@ -482,15 +479,15 @@ static int latest_time_prioq_compare(const void *a, const void *b) {
446ea3
 
446ea3
 static int exit_prioq_compare(const void *a, const void *b) {
446ea3
         const sd_event_source *x = a, *y = b;
446ea3
+        int r;
446ea3
 
446ea3
         assert(x->type == SOURCE_EXIT);
446ea3
         assert(y->type == SOURCE_EXIT);
446ea3
 
446ea3
         /* Enabled ones first */
446ea3
-        if (x->enabled != SD_EVENT_OFF && y->enabled == SD_EVENT_OFF)
446ea3
-                return -1;
446ea3
-        if (x->enabled == SD_EVENT_OFF && y->enabled != SD_EVENT_OFF)
446ea3
-                return 1;
446ea3
+        r = CMP(x->enabled == SD_EVENT_OFF, y->enabled == SD_EVENT_OFF);
446ea3
+        if (r != 0)
446ea3
+                return r;
446ea3
 
446ea3
         /* Lower priority values first */
446ea3
         if (x->priority < y->priority)