update test and header rbtree for correct remove use
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 8 Mar 2010 23:26:15 +0000 (18:26 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 8 Mar 2010 23:26:15 +0000 (18:26 -0500)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
tests/test_urcu_rbtree.c
urcu-rbtree.h

index f7073962935570e5d1a6fe1e036b0c3241960204..bc7a52d68f2efd0417353c9df5e2c9a868e3435e 100644 (file)
@@ -245,6 +245,7 @@ void *thr_writer(void *_count)
 {
        unsigned long long *count = _count;
        struct rcu_rbtree_node *node;
+       void *key;
 
        printf_verbose("thread_begin %s, thread id : %lx, tid %lu\n",
                        "writer", pthread_self(), (unsigned long)gettid());
@@ -261,12 +262,14 @@ void *thr_writer(void *_count)
        for (;;) {
                node = rbtree_alloc();
                rcu_copy_mutex_lock();
-               node->key = (void *)(unsigned long)(rand() % 2048);
+               key = (void *)(unsigned long)(rand() % 2048);
+               node->key = key;
                rcu_rbtree_insert(&rbtree_root, node, tree_comp, rbtree_alloc,
                                  rbtree_free);
                if (unlikely(wduration))
                        loop_sleep(wduration);
 
+               node = rcu_rbtree_search(rbtree_root, key, tree_comp);
                rcu_rbtree_remove(&rbtree_root, node, tree_comp, rbtree_alloc,
                                  rbtree_free);
                defer_rcu((void (*)(void *))rbtree_free, node);
index 8125170df9d31ce05a0a5748a9f9a8a07d3d6a76..954d493268a7d36b700311fcaf91abdc7a01d564 100644 (file)
@@ -84,8 +84,13 @@ int rcu_rbtree_insert(struct rcu_rbtree_node **root,
 /*
  * Remove node from tree.
  * Must wait for a grace period after removal before performing deletion of the
- * node.
+ * node. Note: it is illegal to re-use the same node pointer passed to "insert"
+ * also to "remove", because it may have been copied and garbage-collected since
+ * the insertion. A "search" for the key in the tree should be done to get
+ * "node".
  * Returns 0 on success. May fail with -ENOMEM.
+ *
+ * The caller is responsible for freeing the node after a grace period.
  */
 int rcu_rbtree_remove(struct rcu_rbtree_node **root,
                      struct rcu_rbtree_node *node,
This page took 0.026477 seconds and 4 git commands to generate.