From: Mathieu Desnoyers Date: Sun, 29 May 2011 00:46:13 +0000 (-0400) Subject: Add missing read lock in test, cleanup transplant X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=806967f3116d4b5a84cf38e689afa7031c900349;p=urcu.git Add missing read lock in test, cleanup transplant Signed-off-by: Mathieu Desnoyers --- diff --git a/tests/test_urcu_rbtree.c b/tests/test_urcu_rbtree.c index 9c59726..587db7b 100644 --- a/tests/test_urcu_rbtree.c +++ b/tests/test_urcu_rbtree.c @@ -462,6 +462,8 @@ int main(int argc, char **argv) exit(1); } + rcu_register_thread(); + rcu_read_lock(); /* Insert items looked up by readers */ for (i = 0; i < global_items; i++) { node = rbtree_alloc(); @@ -469,6 +471,7 @@ int main(int argc, char **argv) node->key = global_key[i]; rcu_rbtree_insert(&rbtree, node); } + rcu_read_unlock(); cmm_smp_mb(); @@ -491,12 +494,15 @@ int main(int argc, char **argv) tot_writes += count_writer[i]; } + rcu_read_lock(); for (i = 0; i < global_items; i++) { node = rcu_rbtree_search(&rbtree, rbtree.root, global_key[i]); assert(!rcu_rbtree_is_nil(node)); rcu_rbtree_remove(&rbtree, node); call_rcu(&node->head, rbtree_free); } + rcu_read_unlock(); + rcu_unregister_thread(); printf_verbose("total number of reads : %llu, writes %llu\n", tot_reads, tot_writes); diff --git a/urcu-rbtree.c b/urcu-rbtree.c index d612045..7e1b333 100644 --- a/urcu-rbtree.c +++ b/urcu-rbtree.c @@ -576,17 +576,16 @@ void rcu_rbtree_transplant(struct rcu_rbtree *rbtree, v->p = u->p; cmm_smp_wmb(); /* write into node before publish */ _CMM_STORE_SHARED(rbtree->root, v); - } else if (u == u->p->left) { - v->pos = IS_LEFT; - v->p = u->p; - cmm_smp_wmb(); /* write into node before publish */ - _CMM_STORE_SHARED(u->p->left, v); } else { - v->pos = IS_RIGHT; + v->pos = u->pos; v->p = u->p; cmm_smp_wmb(); /* write into node before publish */ - _CMM_STORE_SHARED(u->p->right, v); + if (u->pos == IS_LEFT) + _CMM_STORE_SHARED(u->p->left, v); + else + _CMM_STORE_SHARED(u->p->right, v); } + /* Point children to new copy (parent only used by updates/next/prev) */ if (!rcu_rbtree_is_nil(v)) { v->right->p = get_decay(v->right->p);