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