X-Git-Url: http://git.liburcu.org/?p=urcu.git;a=blobdiff_plain;f=tests%2Ftest_urcu_defer.c;h=cd9780b6f02f0b44d6f08e5ce5961590ebcde04a;hp=c333964ce9a998c094c5c831476189acce791409;hb=bd252a04bbbb163aa4d8864b1e1e5a3a4d9d0892;hpb=06f22bdbb0c4c4d5db42a2e2dc35818aa61415be diff --git a/tests/test_urcu_defer.c b/tests/test_urcu_defer.c index c333964..cd9780b 100644 --- a/tests/test_urcu_defer.c +++ b/tests/test_urcu_defer.c @@ -31,11 +31,15 @@ #include #include #include -#include #include #include #include +#include + +#ifdef __linux__ +#include +#endif /* hardcoded number of CPUs */ #define NR_CPUS 16384 @@ -152,8 +156,8 @@ static int test_duration_read(void) return !test_stop; } -static unsigned long long __thread nr_writes; -static unsigned long long __thread nr_reads; +static DEFINE_URCU_TLS(unsigned long long, nr_writes); +static DEFINE_URCU_TLS(unsigned long long, nr_reads); static unsigned long long __attribute__((aligned(CAA_CACHE_LINE_SIZE))) *tot_nr_writes; @@ -207,17 +211,17 @@ void *thr_reader(void *_count) debug_yield_read(); if (local_ptr) assert(local_ptr->a == 8); - if (unlikely(rduration)) + if (caa_unlikely(rduration)) loop_sleep(rduration); rcu_read_unlock(); - nr_reads++; - if (unlikely(!test_duration_read())) + URCU_TLS(nr_reads)++; + if (caa_unlikely(!test_duration_read())) break; } rcu_unregister_thread(); - *count = nr_reads; + *count = URCU_TLS(nr_reads); printf_verbose("thread_end %s, thread id : %lx, tid %lu\n", "reader", pthread_self(), (unsigned long)gettid()); return ((void*)1); @@ -236,13 +240,18 @@ void *thr_writer(void *data) { unsigned long wtidx = (unsigned long)data; struct test_array *new, *old = NULL; + int ret; printf_verbose("thread_begin %s, thread id : %lx, tid %lu\n", "writer", 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); + } while (!test_go) { @@ -253,7 +262,7 @@ void *thr_writer(void *data) new = malloc(sizeof(*new)); new->a = 8; old = rcu_xchg_pointer(&test_rcu_pointer, new); - if (unlikely(wduration)) + if (caa_unlikely(wduration)) loop_sleep(wduration); defer_rcu(free, old); defer_rcu(test_cb1, old); @@ -263,10 +272,10 @@ void *thr_writer(void *data) defer_rcu(test_cb2, (void *)-2L); defer_rcu(test_cb2, (void *)-4L); defer_rcu(test_cb2, (void *)-2L); - nr_writes++; - if (unlikely(!test_duration_write())) + URCU_TLS(nr_writes)++; + if (caa_unlikely(!test_duration_write())) break; - if (unlikely(wdelay)) + if (caa_unlikely(wdelay)) loop_sleep(wdelay); } @@ -274,7 +283,7 @@ void *thr_writer(void *data) printf_verbose("thread_end %s, thread id : %lx, tid %lu\n", "writer", pthread_self(), (unsigned long)gettid()); - tot_nr_writes[wtidx] = nr_writes; + tot_nr_writes[wtidx] = URCU_TLS(nr_writes); return ((void*)2); }