{
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());
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);
/*
* 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,