From: Mathieu Desnoyers Date: Mon, 8 Mar 2010 23:26:15 +0000 (-0500) Subject: update test and header rbtree for correct remove use X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=3bc7f395609a073ff46412abeb30bdd5d26dd5c0;p=userspace-rcu.git update test and header rbtree for correct remove use Signed-off-by: Mathieu Desnoyers --- diff --git a/tests/test_urcu_rbtree.c b/tests/test_urcu_rbtree.c index f707396..bc7a52d 100644 --- a/tests/test_urcu_rbtree.c +++ b/tests/test_urcu_rbtree.c @@ -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); diff --git a/urcu-rbtree.h b/urcu-rbtree.h index 8125170..954d493 100644 --- a/urcu-rbtree.h +++ b/urcu-rbtree.h @@ -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,