X-Git-Url: https://git.lttng.org/?p=urcu.git;a=blobdiff_plain;f=tests%2Ftest_rwlock.c;h=1f267e677e48c4e586680ab0c8a8f7dffc11db7f;hp=34d8c0727b271aab00241173154c9c8f825fc4a1;hb=ab0aacbe1a25d50d069f0b24aa492e84ea296f57;hpb=a0b7f7ea3fc3339a1c42caffd53ce9f056e5b901 diff --git a/tests/test_rwlock.c b/tests/test_rwlock.c index 34d8c07..1f267e6 100644 --- a/tests/test_rwlock.c +++ b/tests/test_rwlock.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(); } @@ -156,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 int nr_readers; static unsigned int nr_writers; @@ -204,12 +205,12 @@ void *thr_reader(void *_count) if (caa_unlikely(rduration)) loop_sleep(rduration); pthread_rwlock_unlock(&lock); - nr_reads++; + URCU_TLS(nr_reads)++; if (caa_unlikely(!test_duration_read())) break; } - *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); @@ -237,7 +238,7 @@ void *thr_writer(void *_count) if (caa_unlikely(wduration)) loop_sleep(wduration); pthread_rwlock_unlock(&lock); - nr_writes++; + URCU_TLS(nr_writes)++; if (caa_unlikely(!test_duration_write())) break; if (caa_unlikely(wdelay)) @@ -246,7 +247,7 @@ void *thr_writer(void *_count) 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); }