summaryrefslogtreecommitdiffstats
path: root/meta/recipes-core/systemd/systemd/introduce-ordered_set_clear-free-with-destructor.patch
blob: 42b6e05b5532155ab0be7709c16db06a991e6e3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
From d38a6476aad3f2cc80a2a4bc11f3898cc06a70f5 Mon Sep 17 00:00:00 2001
From: Yu Watanabe <watanabe.yu+github@gmail.com>
Date: Mon, 26 Apr 2021 23:52:40 +0900
Subject: [PATCH] ordered-set: introduce
 ordered_set_clear/free_with_destructor()

Upstream-Status: Backport [https://github.com/systemd/systemd-stable/commit/d38a6476aad3f2cc80a2a4bc11f3898cc06a70f5]
Signed-off-by: Ranjitsinh Rathod <ranjitsinh.rathod@kpit.com>

---
 src/basic/ordered-set.h | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/src/basic/ordered-set.h b/src/basic/ordered-set.h
index a377f20b1f..64df41766f 100644
--- a/src/basic/ordered-set.h
+++ b/src/basic/ordered-set.h
@@ -63,6 +63,17 @@ void ordered_set_print(FILE *f, const char *field, OrderedSet *s);
 #define ORDERED_SET_FOREACH(e, s, i)                                    \
         for ((i) = ITERATOR_FIRST; ordered_set_iterate((s), &(i), (void**)&(e)); )
 
+#define ordered_set_clear_with_destructor(s, f)                 \
+        ({                                                      \
+                OrderedSet *_s = (s);                           \
+                void *_item;                                    \
+                while ((_item = ordered_set_steal_first(_s)))   \
+                        f(_item);                               \
+                _s;                                             \
+        })
+#define ordered_set_free_with_destructor(s, f)                  \
+        ordered_set_free(ordered_set_clear_with_destructor(s, f))
+
 DEFINE_TRIVIAL_CLEANUP_FUNC(OrderedSet*, ordered_set_free);
 DEFINE_TRIVIAL_CLEANUP_FUNC(OrderedSet*, ordered_set_free_free);