X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=tests%2Ftest_mutex.c;h=43d0dace7169d7d8e30ea502400cb2072d1721eb;hb=69328034b804a0fc180c08f7ca6be1a4446bb105;hp=3f84bbfa06fa6c280a0896e4072bdf9ce41b4a6f;hpb=cc6b0c208a9707f8a64609a51167290caeace288;p=urcu.git diff --git a/tests/test_mutex.c b/tests/test_mutex.c index 3f84bbf..43d0dac 100644 --- a/tests/test_mutex.c +++ b/tests/test_mutex.c @@ -35,6 +35,7 @@ #include #include +#include #ifdef __linux__ #include @@ -85,9 +86,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(); } @@ -113,9 +114,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; @@ -155,8 +157,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; @@ -208,12 +210,12 @@ void *thr_reader(void *data) if (caa_unlikely(rduration)) loop_sleep(rduration); pthread_mutex_unlock(&lock); - nr_reads++; + URCU_TLS(nr_reads)++; if (caa_unlikely(!test_duration_read())) break; } - tot_nr_reads[tidx] = nr_reads; + tot_nr_reads[tidx] = URCU_TLS(nr_reads); printf_verbose("thread_end %s, thread id : %lx, tid %lu\n", "reader", pthread_self(), (unsigned long)gettid()); return ((void*)1); @@ -241,7 +243,7 @@ void *thr_writer(void *data) if (caa_unlikely(wduration)) loop_sleep(wduration); pthread_mutex_unlock(&lock); - nr_writes++; + URCU_TLS(nr_writes)++; if (caa_unlikely(!test_duration_write())) break; if (caa_unlikely(wdelay)) @@ -250,7 +252,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); }