X-Git-Url: https://git.liburcu.org/?p=urcu.git;a=blobdiff_plain;f=tests%2Ftest_urcu.c;h=373e1d2df397f0792e55c4be94dbc6e4639e2c80;hp=884d77c472ae28b3a79059d303559932f544b41d;hb=1de4df4b770e5e90440008becc5e14a15c75c6e0;hpb=d4267b0b37f1a7d35e23f0d7c045a973f6c3a6aa diff --git a/tests/test_urcu.c b/tests/test_urcu.c index 884d77c..373e1d2 100644 --- a/tests/test_urcu.c +++ b/tests/test_urcu.c @@ -35,6 +35,7 @@ #include #include +#include #ifdef __linux__ #include @@ -61,7 +62,7 @@ static inline pid_t gettid(void) #ifndef DYNAMIC_LINK_TEST #define _LGPL_SOURCE #else -#define debug_yield_read() +#define rcu_debug_yield_read() #endif #include @@ -83,9 +84,9 @@ static unsigned long rduration; /* write-side C.S. duration, in loops */ static unsigned long wduration; -static inline void loop_sleep(unsigned long l) +static inline void loop_sleep(unsigned long loops) { - while(l-- != 0) + while (loops-- != 0) caa_cpu_relax(); } @@ -111,9 +112,10 @@ typedef unsigned long cpu_set_t; static void set_affinity(void) { +#if HAVE_SCHED_SETAFFINITY cpu_set_t mask; - int cpu; - int ret; + int cpu, ret; +#endif /* HAVE_SCHED_SETAFFINITY */ if (!use_affinity) return; @@ -154,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 int nr_readers; static unsigned int nr_writers; @@ -236,14 +238,14 @@ void *thr_reader(void *_count) for (;;) { rcu_read_lock(); local_ptr = rcu_dereference(test_rcu_pointer); - debug_yield_read(); + rcu_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; } @@ -253,7 +255,7 @@ void *thr_reader(void *_count) rcu_register_thread(); 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); @@ -280,23 +282,23 @@ void *thr_writer(void *_count) new = test_array_alloc(); new->a = 8; old = rcu_xchg_pointer(&test_rcu_pointer, new); - if (unlikely(wduration)) + if (caa_unlikely(wduration)) loop_sleep(wduration); synchronize_rcu(); if (old) old->a = 0; test_array_free(old); rcu_copy_mutex_unlock(); - 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); } printf_verbose("thread_end %s, thread id : %lx, tid %lu\n", "writer", pthread_self(), (unsigned long)gettid()); - *count = nr_writes; + *count = URCU_TLS(nr_writes); return ((void*)2); } @@ -352,10 +354,10 @@ int main(int argc, char **argv) switch (argv[i][1]) { #ifdef DEBUG_YIELD case 'r': - yield_active |= YIELD_READ; + rcu_yield_active |= RCU_YIELD_READ; break; case 'w': - yield_active |= YIELD_WRITE; + rcu_yield_active |= RCU_YIELD_WRITE; break; #endif case 'a':