rculfhash: Add parenthesis around macro arg use in iterator macro
[urcu.git] / urcu / rculfhash.h
index a1ae0f5a8fef9e80e39d8f21750005b565810cd7..06e3eb9cc64d4bc659adb70086662524a3fe8614 100644 (file)
  */
 
 #include <stdint.h>
+#include <urcu/compiler.h>
 #include <urcu-call-rcu.h>
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-
 /*
  * cds_lfht_node: Contains the next pointers and reverse-hash
  * value required for lookup and traversal of the hash table.
@@ -49,7 +49,7 @@ extern "C" {
  * of the hash value for cds_lfht APIs.
  */
 struct cds_lfht_node {
-       struct cds_lfht_node *next;     /* ptr | DUMMY_FLAG | REMOVED_FLAG */
+       struct cds_lfht_node *next;     /* ptr | BUCKET_FLAG | REMOVED_FLAG */
        unsigned long reverse_hash;
 } __attribute__((aligned(4)));
 
@@ -362,6 +362,43 @@ int cds_lfht_del(struct cds_lfht *ht, struct cds_lfht_iter *iter);
  */
 void cds_lfht_resize(struct cds_lfht *ht, unsigned long new_size);
 
+/*
+ * Note: cds_lfht_for_each are safe for element removal during
+ * iteration.
+ */
+#define cds_lfht_for_each(ht, iter, node)                              \
+       for (cds_lfht_first(ht, iter),                                  \
+                       node = cds_lfht_iter_get_node(iter);            \
+               node != NULL;                                           \
+               cds_lfht_next(ht, iter),                                \
+                       node = cds_lfht_iter_get_node(iter))
+
+#define cds_lfht_for_each_duplicate(ht, match, hash, key, iter, node)  \
+       for (cds_lfht_lookup(ht, match, hash, key, iter),               \
+                       node = cds_lfht_iter_get_node(iter);            \
+               node != NULL;                                           \
+               cds_lfht_next_duplicate(ht, match, key, iter),          \
+                       node = cds_lfht_iter_get_node(iter))
+
+#define cds_lfht_for_each_entry(ht, iter, pos, member)                 \
+       for (cds_lfht_first(ht, iter),                                  \
+                       pos = caa_container_of(cds_lfht_iter_get_node(iter), \
+                                       typeof(*(pos)), member);        \
+               &(pos)->member != NULL;                                 \
+               cds_lfht_next(ht, iter),                                \
+                       pos = caa_container_of(cds_lfht_iter_get_node(iter), \
+                                       typeof(*(pos)), member))
+
+#define cds_lfht_for_each_entry_duplicate(ht, match, hash, key,                \
+                               iter, pos, member)                      \
+       for (cds_lfht_lookup(ht, match, hash, key, iter),               \
+                       pos = caa_container_of(cds_lfht_iter_get_node(iter), \
+                                       typeof(*(pos)), member);        \
+               &(pos)->member != NULL;                                 \
+               cds_lfht_next_duplicate(ht, match, key, iter),          \
+                       pos = caa_container_of(cds_lfht_iter_get_node(iter), \
+                                       typeof(*(pos)), member))
+
 #ifdef __cplusplus
 }
 #endif
This page took 0.023714 seconds and 4 git commands to generate.