From: Mathieu Desnoyers Date: Sun, 4 Sep 2011 22:28:03 +0000 (-0400) Subject: rcurbtree: update non-rcu test functions for range-awareness X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=1444707c4feb8a3a31627627acd6aafb75c159e8;p=userspace-rcu.git rcurbtree: update non-rcu test functions for range-awareness Signed-off-by: Mathieu Desnoyers --- diff --git a/urcu-rbtree.c b/urcu-rbtree.c index 4af4ab8..da75e9e 100644 --- a/urcu-rbtree.c +++ b/urcu-rbtree.c @@ -161,7 +161,14 @@ #define RBTREE_RCU_SUPPORT_TRANSPLANT #define RBTREE_RCU_SUPPORT -#ifdef EXTRA_DEBUG +/* + * Add internal mutex locking within the RBTree, for debugging. Enable this + * define and add mutexes to RCU readers to debug races with with rotation or + * transplant. + */ +/* #define RBTREE_INTERNAL_LOCKING */ + +#ifdef RBTREE_INTERNAL_LOCKING static pthread_mutex_t test_mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t outer_mutex = PTHREAD_MUTEX_INITIALIZER; @@ -188,6 +195,26 @@ void unlock_test_mutex(void) { pthread_mutex_unlock(&test_mutex); } +#else +static +void lock_outer_mutex(void) +{ +} + +static +void unlock_outer_mutex(void) +{ +} + +static +void lock_test_mutex(void) +{ +} + +static +void unlock_test_mutex(void) +{ +} #endif static @@ -779,6 +806,16 @@ void left_rotate(struct rcu_rbtree *rbtree, } y->_left = x; set_parent(x, y, IS_LEFT); + + /* + * We only changed the relative position of x and y wrt their + * children, and reparented y (but are keeping the same nodes in + * place, so its parent does not need to have end value + * recalculated). + */ + x->max_end = calculate_node_max_end(rbtree, x); + y->max_end = calculate_node_max_end(rbtree, y); + unlock_test_mutex(); } @@ -892,6 +929,16 @@ void right_rotate(struct rcu_rbtree *rbtree, } y->_right = x; set_parent(x, y, IS_RIGHT); + + /* + * We only changed the relative position of x and y wrt their + * children, and reparented y (but are keeping the same nodes in + * place, so its parent does not need to have end value + * recalculated). + */ + x->max_end = calculate_node_max_end(rbtree, x); + y->max_end = calculate_node_max_end(rbtree, y); + unlock_test_mutex(); } @@ -1089,12 +1136,15 @@ void rcu_rbtree_transplant(struct rcu_rbtree *rbtree, dbg_printf("transplant %p\n", v->begin); lock_test_mutex(); - if (rcu_rbtree_is_nil(rbtree, get_parent(u))) + if (rcu_rbtree_is_nil(rbtree, get_parent(u))) { rbtree->root = v; - else if (u == get_parent(u)->_left) - get_parent(u)->_left = v; - else - get_parent(u)->_right = v; + } else { + if (u == get_parent(u)->_left) + get_parent(u)->_left = v; + else + get_parent(u)->_right = v; + populate_node_end(rbtree, get_parent(u), copy_parents, stop); + } set_parent(v, get_parent(u), get_pos(u)); unlock_test_mutex(); }