Fix tests: use of uninitialized variables
[userspace-rcu.git] / tests / test_urcu_wfs.c
index 4802ee73d7745a73340fa2767f295d605fb10eca..9b6781389d8fdcf3a005fbdbae89a166150adad8 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>
+#include <urcu/tls-compat.h>
+#include "cpuset.h"
+
+#ifdef __linux__
+#include <syscall.h>
+#endif
 
 /* hardcoded number of CPUs */
 #define NR_CPUS 16384
@@ -62,8 +66,7 @@ static inline pid_t gettid(void)
 #define _LGPL_SOURCE
 #endif
 #include <urcu.h>
-#include <urcu/rcuwfstack.h>
-#include <urcu-defer.h>
+#include <urcu/wfstack.h>
 
 static volatile int test_go, test_stop;
 
@@ -77,7 +80,7 @@ static unsigned long wdelay;
 static inline void loop_sleep(unsigned long l)
 {
        while(l-- != 0)
-               cpu_relax();
+               caa_cpu_relax();
 }
 
 static int verbose_mode;
@@ -94,12 +97,6 @@ static int use_affinity = 0;
 
 pthread_mutex_t affinity_mutex = PTHREAD_MUTEX_INITIALIZER;
 
-#ifndef HAVE_CPU_SET_T
-typedef unsigned long cpu_set_t;
-# define CPU_ZERO(cpuset) do { *(cpuset) = 0; } while(0)
-# define CPU_SET(cpu, cpuset) do { *(cpuset) |= (1UL << (cpu)); } while(0)
-#endif
-
 static void set_affinity(void)
 {
        cpu_set_t mask;
@@ -145,57 +142,55 @@ static int test_duration_enqueue(void)
        return !test_stop;
 }
 
-static unsigned long long __thread nr_dequeues;
-static unsigned long long __thread nr_enqueues;
+static DEFINE_URCU_TLS(unsigned long long, nr_dequeues);
+static DEFINE_URCU_TLS(unsigned long long, nr_enqueues);
 
-static unsigned long long __thread nr_successful_dequeues;
-static unsigned long long __thread nr_successful_enqueues;
+static DEFINE_URCU_TLS(unsigned long long, nr_successful_dequeues);
+static DEFINE_URCU_TLS(unsigned long long, nr_successful_enqueues);
 
 static unsigned int nr_enqueuers;
 static unsigned int nr_dequeuers;
 
-static struct rcu_wfs_stack s;
+static struct cds_wfs_stack s;
 
 void *thr_enqueuer(void *_count)
 {
        unsigned long long *count = _count;
 
        printf_verbose("thread_begin %s, thread id : %lx, tid %lu\n",
-                       "enqueuer", pthread_self(), (unsigned long)gettid());
+                       "enqueuer", (unsigned long) pthread_self(),
+                       (unsigned long) gettid());
 
        set_affinity();
 
-       rcu_register_thread();
-
        while (!test_go)
        {
        }
-       smp_mb();
+       cmm_smp_mb();
 
        for (;;) {
-               struct rcu_wfs_node *node = malloc(sizeof(*node));
+               struct cds_wfs_node *node = malloc(sizeof(*node));
                if (!node)
                        goto fail;
-               rcu_wfs_node_init(node);
-               rcu_wfs_push(&s, node);
-               nr_successful_enqueues++;
+               cds_wfs_node_init(node);
+               cds_wfs_push(&s, node);
+               URCU_TLS(nr_successful_enqueues)++;
 
-               if (unlikely(wdelay))
+               if (caa_unlikely(wdelay))
                        loop_sleep(wdelay);
 fail:
-               nr_enqueues++;
-               if (unlikely(!test_duration_enqueue()))
+               URCU_TLS(nr_enqueues)++;
+               if (caa_unlikely(!test_duration_enqueue()))
                        break;
        }
 
-       rcu_unregister_thread();
-
-       count[0] = nr_enqueues;
-       count[1] = nr_successful_enqueues;
+       count[0] = URCU_TLS(nr_enqueues);
+       count[1] = URCU_TLS(nr_successful_enqueues);
        printf_verbose("enqueuer thread_end, thread id : %lx, tid %lu, "
                       "enqueues %llu successful_enqueues %llu\n",
-                      pthread_self(), (unsigned long)gettid(), nr_enqueues,
-                      nr_successful_enqueues);
+                      (unsigned long) pthread_self(),
+                       (unsigned long) gettid(),
+                      URCU_TLS(nr_enqueues), URCU_TLS(nr_successful_enqueues));
        return ((void*)1);
 
 }
@@ -205,51 +200,47 @@ void *thr_dequeuer(void *_count)
        unsigned long long *count = _count;
 
        printf_verbose("thread_begin %s, thread id : %lx, tid %lu\n",
-                       "dequeuer", pthread_self(), (unsigned long)gettid());
+                       "dequeuer", (unsigned long) pthread_self(),
+                       (unsigned long) gettid());
 
        set_affinity();
 
-       rcu_defer_register_thread();
-       rcu_register_thread();
-
        while (!test_go)
        {
        }
-       smp_mb();
+       cmm_smp_mb();
 
        for (;;) {
-               struct rcu_wfs_node *node = rcu_wfs_pop(&s);
+               struct cds_wfs_node *node = cds_wfs_pop_blocking(&s);
 
                if (node) {
-                       defer_rcu(free, node);
-                       nr_successful_dequeues++;
+                       free(node);
+                       URCU_TLS(nr_successful_dequeues)++;
                }
 
-               nr_dequeues++;
-               if (unlikely(!test_duration_dequeue()))
+               URCU_TLS(nr_dequeues)++;
+               if (caa_unlikely(!test_duration_dequeue()))
                        break;
-               if (unlikely(rduration))
+               if (caa_unlikely(rduration))
                        loop_sleep(rduration);
        }
 
-       rcu_unregister_thread();
-       rcu_defer_unregister_thread();
-
        printf_verbose("dequeuer thread_end, thread id : %lx, tid %lu, "
                       "dequeues %llu, successful_dequeues %llu\n",
-                      pthread_self(), (unsigned long)gettid(), nr_dequeues,
-                      nr_successful_dequeues);
-       count[0] = nr_dequeues;
-       count[1] = nr_successful_dequeues;
+                      (unsigned long) pthread_self(),
+                       (unsigned long) gettid(),
+                      URCU_TLS(nr_dequeues), URCU_TLS(nr_successful_dequeues));
+       count[0] = URCU_TLS(nr_dequeues);
+       count[1] = URCU_TLS(nr_successful_dequeues);
        return ((void*)2);
 }
 
-void test_end(struct rcu_wfs_stack *s, unsigned long long *nr_dequeues)
+void test_end(struct cds_wfs_stack *s, unsigned long long *nr_dequeues)
 {
-       struct rcu_wfs_node *node;
+       struct cds_wfs_node *node;
 
        do {
-               node = rcu_wfs_pop(s);
+               node = cds_wfs_pop_blocking(s);
                if (node) {
                        free(node);
                        (*nr_dequeues)++;
@@ -342,13 +333,14 @@ int main(int argc, char **argv)
        printf_verbose("Writer delay : %lu loops.\n", rduration);
        printf_verbose("Reader duration : %lu loops.\n", wdelay);
        printf_verbose("thread %-6s, thread id : %lx, tid %lu\n",
-                       "main", pthread_self(), (unsigned long)gettid());
+                       "main", (unsigned long) pthread_self(),
+                       (unsigned long) gettid());
 
-       tid_enqueuer = malloc(sizeof(*tid_enqueuer) * nr_enqueuers);
-       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_wfs_init(&s);
+       tid_enqueuer = calloc(nr_enqueuers, sizeof(*tid_enqueuer));
+       tid_dequeuer = calloc(nr_dequeuers, sizeof(*tid_dequeuer));
+       count_enqueuer = calloc(nr_enqueuers, 2 * sizeof(*count_enqueuer));
+       count_dequeuer = calloc(nr_dequeuers, 2 * sizeof(*count_dequeuer));
+       cds_wfs_init(&s);
 
        next_aff = 0;
 
@@ -365,7 +357,7 @@ int main(int argc, char **argv)
                        exit(1);
        }
 
-       smp_mb();
+       cmm_smp_mb();
 
        test_go = 1;
 
This page took 0.025711 seconds and 4 git commands to generate.