X-Git-Url: https://git.liburcu.org/?a=blobdiff_plain;f=tests%2Ftest_rwlock.c;h=b787364ee8023045220ab2c868b2a8da3682b5e9;hb=b5002bee0cfd9fab20edc7d2bfaa9d0c75628f5b;hp=34d8c0727b271aab00241173154c9c8f825fc4a1;hpb=a0b7f7ea3fc3339a1c42caffd53ce9f056e5b901;p=urcu.git diff --git a/tests/test_rwlock.c b/tests/test_rwlock.c index 34d8c07..b787364 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(); } @@ -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; @@ -156,8 +158,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; @@ -190,7 +192,8 @@ void *thr_reader(void *_count) unsigned long long *count = _count; printf_verbose("thread_begin %s, thread id : %lx, tid %lu\n", - "reader", pthread_self(), (unsigned long)gettid()); + "reader", (unsigned long) pthread_self(), + (unsigned long) gettid()); set_affinity(); @@ -204,14 +207,15 @@ 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()); + "reader", (unsigned long) pthread_self(), + (unsigned long) gettid()); return ((void*)1); } @@ -221,7 +225,8 @@ void *thr_writer(void *_count) unsigned long long *count = _count; printf_verbose("thread_begin %s, thread id : %lx, tid %lu\n", - "writer", pthread_self(), (unsigned long)gettid()); + "writer", (unsigned long) pthread_self(), + (unsigned long) gettid()); set_affinity(); @@ -237,7 +242,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)) @@ -245,8 +250,9 @@ 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; + "writer", (unsigned long) pthread_self(), + (unsigned long) gettid()); + *count = URCU_TLS(nr_writes); return ((void*)2); } @@ -351,7 +357,8 @@ int main(int argc, char **argv) printf_verbose("Writer delay : %lu loops.\n", wdelay); printf_verbose("Reader duration : %lu loops.\n", rduration); 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_reader = malloc(sizeof(*tid_reader) * nr_readers); tid_writer = malloc(sizeof(*tid_writer) * nr_writers);