diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2021-04-26 16:52:40 +0200 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2021-05-12 03:30:45 +0200 |
commit | d38a6476aad3f2cc80a2a4bc11f3898cc06a70f5 (patch) | |
tree | cd92b5d9f27aab3b3255cdca9336dcf742391813 /src/basic/ordered-set.h | |
parent | hashmap,set: make hashmap_clear_with_destructor() or friends safer (diff) | |
download | systemd-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.h | 11 |
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); |