From 0bd215cc178dcbd1db3959116a0a89ef6633a377 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Mon, 30 May 2011 16:23:56 -0400 Subject: [PATCH] RBtree: move wmb after node write We need to write all the new info into the node before we publish it (make it visible to readers). Signed-off-by: Mathieu Desnoyers --- urcu-rbtree.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/urcu-rbtree.c b/urcu-rbtree.c index cb823b2..c0550d1 100644 --- a/urcu-rbtree.c +++ b/urcu-rbtree.c @@ -915,17 +915,21 @@ int rcu_rbtree_insert(struct rcu_rbtree *rbtree, else set_parent(z, y, IS_RIGHT); - /* - * Order stores to z (children/parents) before stores that will make it - * visible to the rest of the tree. - */ - cmm_smp_wmb(); - if (rcu_rbtree_is_nil(rbtree, y)) { + /* + * Order stores to z (children/parents) before stores + * that will make it visible to the rest of the tree. + */ + cmm_smp_wmb(); _CMM_STORE_SHARED(rbtree->root, z); } else if (rbtree->comp(z->key, y->key) < 0) { set_left_dup_decay(rbtree, y, z, &top, &top_child, &top_child_pos); + /* + * Order stores to z (children/parents) before stores + * that will make it visible to the rest of the tree. + */ + cmm_smp_wmb(); if (rcu_rbtree_is_nil(rbtree, top)) _CMM_STORE_SHARED(rbtree->root, top_child); else if (top_child_pos == IS_LEFT) @@ -936,6 +940,11 @@ int rcu_rbtree_insert(struct rcu_rbtree *rbtree, } else { set_right_dup_decay(rbtree, y, z, &top, &top_child, &top_child_pos); + /* + * Order stores to z (children/parents) before stores + * that will make it visible to the rest of the tree. + */ + cmm_smp_wmb(); if (rcu_rbtree_is_nil(rbtree, top)) _CMM_STORE_SHARED(rbtree->root, top_child); else if (top_child_pos == IS_LEFT) @@ -981,7 +990,6 @@ void rcu_rbtree_transplant(struct rcu_rbtree *rbtree, _CMM_STORE_SHARED(rbtree->root, v); } else { set_parent(v, get_parent(u), get_pos(u)); - cmm_smp_wmb(); /* write into node before publish */ if (get_pos(u) == IS_LEFT) { _set_left_dup_decay(rbtree, get_parent(u), v, @@ -993,6 +1001,8 @@ void rcu_rbtree_transplant(struct rcu_rbtree *rbtree, &top, &top_child, &top_child_pos); } + cmm_smp_wmb(); /* write into node before publish */ + if (rcu_rbtree_is_nil(rbtree, top)) _CMM_STORE_SHARED(rbtree->root, top_child); else if (top_child_pos == IS_LEFT) -- 2.34.1