RCU rbtree test: handle duplicate random numbers
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 30 May 2011 02:42:29 +0000 (22:42 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 30 May 2011 02:42:29 +0000 (22:42 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
tests/test_urcu_rbtree.c

index e0beb6ffcdfa59ecb85728336f7e84d635dd6336..c26ac6da8d6f456cf66f222aa6aef5eec1c8c1c7 100644 (file)
@@ -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();
This page took 0.025249 seconds and 4 git commands to generate.