[ovs-discuss] [ACLv2 18/19] hmap: Add HMAP_FOR_EACH_WITH_HASH_SAFE.
Jesse Gross
jesse at nicira.com
Sat Aug 15 02:13:26 UTC 2009
Add a _SAFE version of the macro to allow callers to delete entries
as they are iterating over matching entries.
---
lib/hmap.h | 9 +++++++++
1 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/lib/hmap.h b/lib/hmap.h
index 1809a91..60890b1 100644
--- a/lib/hmap.h
+++ b/lib/hmap.h
@@ -74,6 +74,15 @@ static inline void hmap_replace(struct hmap *, const struct hmap_node *old,
(NODE) = CONTAINER_OF(hmap_next_with_hash(&(NODE)->MEMBER), \
STRUCT, MEMBER))
+#define HMAP_FOR_EACH_WITH_HASH_SAFE(NODE, NEXT, STRUCT, MEMBER, HASH, HMAP) \
+ for ((NODE) = CONTAINER_OF(hmap_first_with_hash(HMAP, HASH), \
+ STRUCT, MEMBER); \
+ (&(NODE)->MEMBER != NULL \
+ ? (NEXT) = CONTAINER_OF(hmap_next_with_hash(&(NODE)->MEMBER), \
+ STRUCT, MEMBER), 1 \
+ : 0); \
+ (NODE) = (NEXT))
+
static inline struct hmap_node *hmap_first_with_hash(const struct hmap *,
size_t hash);
static inline struct hmap_node *hmap_next_with_hash(const struct hmap_node *);
--
1.6.0.4
More information about the discuss
mailing list