Basic fix for rbtree nil root and urcu defer registration
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 8 Mar 2010 23:09:13 +0000 (18:09 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 8 Mar 2010 23:09:13 +0000 (18:09 -0500)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
tests/test_urcu_rbtree.c

index d42279b567fbf8c16fd5a38f2ec67b851465c428..043ec7121f12bb1edbe834d864d700a667a5af78 100644 (file)
@@ -34,6 +34,7 @@
 #include <sys/syscall.h>
 #include <sched.h>
 #include <errno.h>
+#include <time.h>
 
 #include <urcu/arch.h>
 
@@ -62,8 +63,9 @@ static inline pid_t gettid(void)
 #endif
 #include <urcu.h>
 #include <urcu-rbtree.h>
+#include <urcu-defer.h>
 
-static struct rcu_rbtree_node *rbtree_root;
+static struct rcu_rbtree_node *rbtree_root = &rcu_rbtree_nil;
 
 /* TODO: error handling testing for -ENOMEM */
 struct rcu_rbtree_node *rbtree_alloc(void)
@@ -71,9 +73,19 @@ struct rcu_rbtree_node *rbtree_alloc(void)
        return malloc(sizeof(struct rcu_rbtree_node));
 }
 
-struct rcu_rbtree_node *rbtree_free(struct rcu_rbtree_node *node)
+void rbtree_free(struct rcu_rbtree_node *node)
 {
-       return free(node);
+       free(node);
+}
+
+int tree_comp(void *a, void *b)
+{
+       if ((unsigned long)a < (unsigned long)b)
+               return -1;
+       else if ((unsigned long)a > (unsigned long)b)
+               return 1;
+       else
+               return 0;
 }
 
 static volatile int test_go, test_stop;
@@ -232,22 +244,30 @@ void *thr_reader(void *_count)
 void *thr_writer(void *_count)
 {
        unsigned long long *count = _count;
+       struct rcu_rbtree_node *node;
 
        printf_verbose("thread_begin %s, thread id : %lx, tid %lu\n",
                        "writer", pthread_self(), (unsigned long)gettid());
 
        set_affinity();
 
+       rcu_defer_register_thread();
+
        while (!test_go)
        {
        }
        smp_mb();
 
        for (;;) {
-
+               node = rbtree_alloc();
+               rcu_copy_mutex_lock();
+               node->key = (void *)(unsigned long)(rand() % 2048);
+               rcu_rbtree_insert(&rbtree_root, node, tree_comp, rbtree_alloc,
+                                 rbtree_free);
                if (unlikely(wduration))
                        loop_sleep(wduration);
 
+               rcu_copy_mutex_unlock();
                nr_writes++;
                if (unlikely(!test_duration_write()))
                        break;
@@ -255,6 +275,8 @@ void *thr_writer(void *_count)
                        loop_sleep(wdelay);
        }
 
+       rcu_defer_unregister_thread();
+
        printf_verbose("thread_end %s, thread id : %lx, tid %lu\n",
                        "writer", pthread_self(), (unsigned long)gettid());
        *count = nr_writes;
@@ -368,6 +390,8 @@ int main(int argc, char **argv)
        count_reader = malloc(sizeof(*count_reader) * nr_readers);
        count_writer = malloc(sizeof(*count_writer) * nr_writers);
 
+       srand(time(NULL));
+
        next_aff = 0;
 
        for (i = 0; i < nr_readers; i++) {
This page took 0.0267 seconds and 4 git commands to generate.