summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/openvswitch/hmap.h26
-rw-r--r--include/openvswitch/shash.h15
2 files changed, 35 insertions, 6 deletions
diff --git a/include/openvswitch/hmap.h b/include/openvswitch/hmap.h
index 68c284cf1..beb48295b 100644
--- a/include/openvswitch/hmap.h
+++ b/include/openvswitch/hmap.h
@@ -178,18 +178,36 @@ bool hmap_contains(const struct hmap *, const struct hmap_node *);
/* Safe when NODE may be freed (not needed when NODE may be removed from the
* hash map but its members remain accessible and intact). */
-#define HMAP_FOR_EACH_SAFE(NODE, NEXT, MEMBER, HMAP) \
- HMAP_FOR_EACH_SAFE_INIT (NODE, NEXT, MEMBER, HMAP, (void) NEXT)
+#define HMAP_FOR_EACH_SAFE_LONG(NODE, NEXT, MEMBER, HMAP) \
+ HMAP_FOR_EACH_SAFE_LONG_INIT (NODE, NEXT, MEMBER, HMAP, (void) NEXT)
-#define HMAP_FOR_EACH_SAFE_INIT(NODE, NEXT, MEMBER, HMAP, ...) \
+#define HMAP_FOR_EACH_SAFE_LONG_INIT(NODE, NEXT, MEMBER, HMAP, ...) \
for (INIT_MULTIVAR_SAFE_LONG_EXP(NODE, NEXT, MEMBER, hmap_first(HMAP), \
- struct hmap_node, __VA_ARGS__); \
+ struct hmap_node, __VA_ARGS__); \
CONDITION_MULTIVAR_SAFE_LONG(NODE, NEXT, MEMBER, \
ITER_VAR(NODE) != NULL, \
ITER_VAR(NEXT) = hmap_next(HMAP, ITER_VAR(NODE)), \
ITER_VAR(NEXT) != NULL); \
UPDATE_MULTIVAR_SAFE_LONG(NODE, NEXT))
+/* Short versions of HMAP_FOR_EACH_SAFE. */
+#define HMAP_FOR_EACH_SAFE_SHORT(NODE, MEMBER, HMAP) \
+ HMAP_FOR_EACH_SAFE_SHORT_INIT (NODE, MEMBER, HMAP, (void) 0)
+
+#define HMAP_FOR_EACH_SAFE_SHORT_INIT(NODE, MEMBER, HMAP, ...) \
+ for (INIT_MULTIVAR_SAFE_SHORT_EXP(NODE, MEMBER, hmap_first(HMAP), \
+ struct hmap_node, __VA_ARGS__); \
+ CONDITION_MULTIVAR_SAFE_SHORT(NODE, MEMBER, \
+ ITER_VAR(NODE) != NULL, \
+ ITER_NEXT_VAR(NODE) = hmap_next(HMAP, ITER_VAR(NODE))); \
+ UPDATE_MULTIVAR_SAFE_SHORT(NODE))
+
+#define HMAP_FOR_EACH_SAFE(...) \
+ OVERLOAD_SAFE_MACRO(HMAP_FOR_EACH_SAFE_LONG, \
+ HMAP_FOR_EACH_SAFE_SHORT, \
+ 4, __VA_ARGS__)
+
+
/* Continues an iteration from just after NODE. */
#define HMAP_FOR_EACH_CONTINUE(NODE, MEMBER, HMAP) \
HMAP_FOR_EACH_CONTINUE_INIT(NODE, MEMBER, HMAP, (void) 0)
diff --git a/include/openvswitch/shash.h b/include/openvswitch/shash.h
index c249e13e1..4e7badd4d 100644
--- a/include/openvswitch/shash.h
+++ b/include/openvswitch/shash.h
@@ -41,13 +41,24 @@ struct shash {
BUILD_ASSERT_TYPE(SHASH_NODE, struct shash_node *), \
BUILD_ASSERT_TYPE(SHASH, struct shash *))
-#define SHASH_FOR_EACH_SAFE(SHASH_NODE, NEXT, SHASH) \
- HMAP_FOR_EACH_SAFE_INIT ( \
+#define SHASH_FOR_EACH_SAFE_SHORT(SHASH_NODE, SHASH) \
+ HMAP_FOR_EACH_SAFE_SHORT_INIT ( \
+ SHASH_NODE, node, &(SHASH)->map, \
+ BUILD_ASSERT_TYPE(SHASH_NODE, struct shash_node *), \
+ BUILD_ASSERT_TYPE(SHASH, struct shash *))
+
+#define SHASH_FOR_EACH_SAFE_LONG(SHASH_NODE, NEXT, SHASH) \
+ HMAP_FOR_EACH_SAFE_LONG_INIT ( \
SHASH_NODE, NEXT, node, &(SHASH)->map, \
BUILD_ASSERT_TYPE(SHASH_NODE, struct shash_node *), \
BUILD_ASSERT_TYPE(NEXT, struct shash_node *), \
BUILD_ASSERT_TYPE(SHASH, struct shash *))
+#define SHASH_FOR_EACH_SAFE(...) \
+ OVERLOAD_SAFE_MACRO(SHASH_FOR_EACH_SAFE_LONG, \
+ SHASH_FOR_EACH_SAFE_SHORT, \
+ 3, __VA_ARGS__)
+
void shash_init(struct shash *);
void shash_destroy(struct shash *);
void shash_destroy_free_data(struct shash *);