Add cds_lfht_first/cds_lfht_next for hash table iteration
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 27 Sep 2011 21:24:55 +0000 (17:24 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 27 Sep 2011 21:24:55 +0000 (17:24 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
rculfhash.c
urcu/rculfhash.h

index 50b783440edc6e4297cd1ac341bd15ce780f5045..c7a429e6902fa521ff0d72d2d62e6f194878ad66 100644 (file)
@@ -1391,6 +1391,44 @@ void cds_lfht_next_duplicate(struct cds_lfht *ht, struct cds_lfht_iter *iter)
        iter->next = next;
 }
 
+void cds_lfht_next(struct cds_lfht *ht, struct cds_lfht_iter *iter)
+{
+       struct cds_lfht_node *node, *next;
+
+       node = iter->node;
+       next = iter->next;
+       node = clear_flag(next);
+
+       for (;;) {
+               if (unlikely(is_end(node))) {
+                       node = next = NULL;
+                       break;
+               }
+               next = rcu_dereference(node->p.next);
+               if (likely(!is_removed(next))
+                   && !is_dummy(next)) {
+                               break;
+               }
+               node = clear_flag(next);
+       }
+       assert(!node || !is_dummy(rcu_dereference(node->p.next)));
+       iter->node = node;
+       iter->next = next;
+}
+
+void cds_lfht_first(struct cds_lfht *ht, struct cds_lfht_iter *iter)
+{
+       struct _cds_lfht_node *lookup;
+
+       /*
+        * Get next after first dummy node. The first dummy node is the
+        * first node of the linked list.
+        */
+       lookup = &ht->t.tbl[0]->nodes[0];
+       iter->node = (struct cds_lfht_node *) lookup;
+       cds_lfht_next(ht, iter);
+}
+
 void cds_lfht_add(struct cds_lfht *ht, struct cds_lfht_node *node)
 {
        unsigned long hash, size;
index 5e149ef629de692fbc5b1f4aeed371269d18b2b4..0a739ee86f7d11b1e9caa4b8bbb9091dbc0ff1b9 100644 (file)
@@ -197,6 +197,23 @@ void cds_lfht_lookup(struct cds_lfht *ht, void *key, size_t key_len,
  */
 void cds_lfht_next_duplicate(struct cds_lfht *ht, struct cds_lfht_iter *iter);
 
+/*
+ * cds_lfht_first - get the first node in the table.
+ *
+ * Output in "*iter". *iter->node set to NULL if table is empty.
+ * Call with rcu_read_lock held.
+ */
+void cds_lfht_first(struct cds_lfht *ht, struct cds_lfht_iter *iter);
+
+/*
+ * cds_lfht_next - get the next node in the table.
+ *
+ * Input/Output in "*iter". *iter->node set to NULL if *iter was
+ * pointing to the last table node.
+ * Call with rcu_read_lock held.
+ */
+void cds_lfht_next(struct cds_lfht *ht, struct cds_lfht_iter *iter);
+
 /*
  * cds_lfht_add - add a node to the hash table.
  *
This page took 0.027394 seconds and 4 git commands to generate.