#include <sys/syscall.h>
#include <sched.h>
#include <errno.h>
+#include <time.h>
#include <urcu/arch.h>
#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)
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;
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;
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;
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++) {