summaryrefslogtreecommitdiffstats
path: root/src/basic/ordered-set.h
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2021-04-26 16:52:40 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2021-05-12 03:30:45 +0200
commitd38a6476aad3f2cc80a2a4bc11f3898cc06a70f5 (patch)
treecd92b5d9f27aab3b3255cdca9336dcf742391813 /src/basic/ordered-set.h
parenthashmap,set: make hashmap_clear_with_destructor() or friends safer (diff)
downloadsystemd-d38a6476aad3f2cc80a2a4bc11f3898cc06a70f5.tar.xz
systemd-d38a6476aad3f2cc80a2a4bc11f3898cc06a70f5.zip
ordered-set: introduce ordered_set_clear/free_with_destructor()
Diffstat (limited to '')
-rw-r--r--src/basic/ordered-set.h11
1 files changed, 11 insertions, 0 deletions
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
@@ -75,6 +75,17 @@ void ordered_set_print(FILE *f, const char *field, OrderedSet *s);
#define ORDERED_SET_FOREACH(e, s) \
_ORDERED_SET_FOREACH(e, s, UNIQ_T(i, UNIQ))
+#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);