tests: only include syscall.h on linux systems
[urcu.git] / tests / test_urcu_lfs.c
index 02be2d4d61a75e7248e4d80f79df6066f65e76db..252454d29aeb46d4758e30b2a7f6b864cc8e3b65 100644 (file)
 #include <unistd.h>
 #include <stdio.h>
 #include <assert.h>
-#include <sys/syscall.h>
 #include <sched.h>
 #include <errno.h>
 
 #include <urcu/arch.h>
 
+#ifdef __linux__
+#include <syscall.h>
+#endif
+
 /* hardcoded number of CPUs */
 #define NR_CPUS 16384
 
@@ -62,7 +65,7 @@ static inline pid_t gettid(void)
 #define _LGPL_SOURCE
 #endif
 #include <urcu.h>
-#include <urcu/rculfstack.h>
+#include <urcu/cds.h>
 #include <urcu-defer.h>
 
 static volatile int test_go, test_stop;
@@ -154,7 +157,7 @@ static unsigned long long __thread nr_successful_enqueues;
 static unsigned int nr_enqueuers;
 static unsigned int nr_dequeuers;
 
-static struct rcu_lfs_stack s;
+static struct cds_lfs_stack_rcu s;
 
 void *thr_enqueuer(void *_count)
 {
@@ -173,11 +176,12 @@ void *thr_enqueuer(void *_count)
        cmm_smp_mb();
 
        for (;;) {
-               struct rcu_lfs_node *node = malloc(sizeof(*node));
+               struct cds_lfs_node_rcu *node = malloc(sizeof(*node));
                if (!node)
                        goto fail;
-               rcu_lfs_node_init(node);
-               rcu_lfs_push(&s, node);
+               cds_lfs_node_init_rcu(node);
+               /* No rcu read-side is needed for push */
+               cds_lfs_push_rcu(&s, node);
                nr_successful_enqueues++;
 
                if (unlikely(wdelay))
@@ -203,13 +207,18 @@ fail:
 void *thr_dequeuer(void *_count)
 {
        unsigned long long *count = _count;
+       int ret;
 
        printf_verbose("thread_begin %s, thread id : %lx, tid %lu\n",
                        "dequeuer", pthread_self(), (unsigned long)gettid());
 
        set_affinity();
 
-       rcu_defer_register_thread();
+       ret = rcu_defer_register_thread();
+       if (ret) {
+               printf("Error in rcu_defer_register_thread\n");
+               exit(-1);
+       }
        rcu_register_thread();
 
        while (!test_go)
@@ -218,13 +227,15 @@ void *thr_dequeuer(void *_count)
        cmm_smp_mb();
 
        for (;;) {
-               struct rcu_lfs_node *node = rcu_lfs_pop(&s);
+               struct cds_lfs_node_rcu *node;
 
+               rcu_read_lock();
+               node = cds_lfs_pop_rcu(&s);
+               rcu_read_unlock();
                if (node) {
                        defer_rcu(free, node);
                        nr_successful_dequeues++;
                }
-
                nr_dequeues++;
                if (unlikely(!test_duration_dequeue()))
                        break;
@@ -244,12 +255,12 @@ void *thr_dequeuer(void *_count)
        return ((void*)2);
 }
 
-void test_end(struct rcu_lfs_stack *s, unsigned long long *nr_dequeues)
+void test_end(struct cds_lfs_stack_rcu *s, unsigned long long *nr_dequeues)
 {
-       struct rcu_lfs_node *node;
+       struct cds_lfs_node_rcu *node;
 
        do {
-               node = rcu_lfs_pop(s);
+               node = cds_lfs_pop_rcu(s);
                if (node) {
                        free(node);
                        (*nr_dequeues)++;
@@ -348,7 +359,7 @@ int main(int argc, char **argv)
        tid_dequeuer = malloc(sizeof(*tid_dequeuer) * nr_dequeuers);
        count_enqueuer = malloc(2 * sizeof(*count_enqueuer) * nr_enqueuers);
        count_dequeuer = malloc(2 * sizeof(*count_dequeuer) * nr_dequeuers);
-       rcu_lfs_init(&s);
+       cds_lfs_init_rcu(&s);
 
        next_aff = 0;
 
This page took 0.039888 seconds and 4 git commands to generate.