From: Mathieu Desnoyers Date: Mon, 30 May 2011 02:42:29 +0000 (-0400) Subject: RCU rbtree test: handle duplicate random numbers X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=f6f3275737efd51920e34e521087bf49d708e065;p=userspace-rcu.git RCU rbtree test: handle duplicate random numbers Signed-off-by: Mathieu Desnoyers --- diff --git a/tests/test_urcu_rbtree.c b/tests/test_urcu_rbtree.c index e0beb6f..c26ac6d 100644 --- a/tests/test_urcu_rbtree.c +++ b/tests/test_urcu_rbtree.c @@ -210,15 +210,18 @@ void rcu_copy_mutex_unlock(void) } static -int lookup_index(struct rcu_rbtree_node *node) +void set_lookup_index(struct rcu_rbtree_node *node, + char *lookup_hit) { int i; for (i = 0; i < global_items; i++) { - if (node->key == global_key[i]) - return i; + if (node->key == global_key[i] + && !lookup_hit[i]) { + lookup_hit[i] = 1; + break; + } } - return -1; } void *thr_reader(void *_count) @@ -260,9 +263,7 @@ void *thr_reader(void *_count) node = rcu_rbtree_min(&rbtree, rcu_dereference(rbtree.root)); while (!rcu_rbtree_is_nil(node)) { - index = lookup_index(node); - if (index >= 0) - lookup_hit[index] = 1; + set_lookup_index(node, lookup_hit); node = rcu_rbtree_next(&rbtree, node); } rcu_read_unlock(); @@ -277,9 +278,7 @@ void *thr_reader(void *_count) node = rcu_rbtree_max(&rbtree, rcu_dereference(rbtree.root)); while (!rcu_rbtree_is_nil(node)) { - index = lookup_index(node); - if (index >= 0) - lookup_hit[index] = 1; + set_lookup_index(node, lookup_hit); node = rcu_rbtree_prev(&rbtree, node); } rcu_read_unlock();