Use urcu/tls-compat.h
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 16 May 2012 13:42:55 +0000 (09:42 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 16 May 2012 13:42:55 +0000 (09:42 -0400)
Provides compatibility for OpenBSD, NetBSD and Darwin.

Suggested-by: Marek VavruĊĦa <marek.vavrusa@nic.cz>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
26 files changed:
tests/test_mutex.c
tests/test_perthreadlock.c
tests/test_rwlock.c
tests/test_urcu.c
tests/test_urcu_assign.c
tests/test_urcu_bp.c
tests/test_urcu_defer.c
tests/test_urcu_gc.c
tests/test_urcu_hash.c
tests/test_urcu_hash.h
tests/test_urcu_hash_rw.c
tests/test_urcu_hash_unique.c
tests/test_urcu_lfq.c
tests/test_urcu_lfs.c
tests/test_urcu_qsbr.c
tests/test_urcu_qsbr_gc.c
tests/test_urcu_wfq.c
tests/test_urcu_wfs.c
urcu-bp.c
urcu-call-rcu-impl.h
urcu-defer-impl.h
urcu-qsbr.c
urcu.c
urcu/static/urcu-bp.h
urcu/static/urcu-qsbr.h
urcu/static/urcu.h

index 3f84bbfa06fa6c280a0896e4072bdf9ce41b4a6f..ba184a47e241ee2fd0cedb6eca326d805bcd3fac 100644 (file)
@@ -35,6 +35,7 @@
 #include <errno.h>
 
 #include <urcu/arch.h>
+#include <urcu/tls-compat.h>
 
 #ifdef __linux__
 #include <syscall.h>
@@ -155,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;
@@ -208,12 +209,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 +242,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 +251,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);
 }
 
index fa9c89a5e560e452f9768ef90fffbd795f16cb84..6ff04120e4e73ce07931b1ace6215fba35044a61 100644 (file)
@@ -35,6 +35,7 @@
 #include <errno.h>
 
 #include <urcu/arch.h>
+#include <urcu/tls-compat.h>
 
 #ifdef __linux__
 #include <syscall.h>
@@ -159,8 +160,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;
@@ -212,12 +213,12 @@ void *thr_reader(void *data)
                if (caa_unlikely(rduration))
                        loop_sleep(rduration);
                pthread_mutex_unlock(&per_thread_lock[tidx].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);
@@ -250,7 +251,7 @@ void *thr_writer(void *data)
                for (tidx = (long)nr_readers - 1; tidx >= 0; tidx--) {
                        pthread_mutex_unlock(&per_thread_lock[tidx].lock);
                }
-               nr_writes++;
+               URCU_TLS(nr_writes)++;
                if (caa_unlikely(!test_duration_write()))
                        break;
                if (caa_unlikely(wdelay))
@@ -259,7 +260,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);
 }
 
index 34d8c0727b271aab00241173154c9c8f825fc4a1..ccbc9d170c9e226dab54944881095f8c1599b39d 100644 (file)
@@ -35,6 +35,7 @@
 #include <errno.h>
 
 #include <urcu/arch.h>
+#include <urcu/tls-compat.h>
 
 #ifdef __linux__
 #include <syscall.h>
@@ -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);
 }
 
index 870f133ab75f82b03f997cea1518f9e1979e4403..1b1b94b5bfcebc77c3fec5481e528858d62ed4f9 100644 (file)
@@ -35,6 +35,7 @@
 #include <errno.h>
 
 #include <urcu/arch.h>
+#include <urcu/tls-compat.h>
 
 #ifdef __linux__
 #include <syscall.h>
@@ -154,8 +155,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;
@@ -242,7 +243,7 @@ void *thr_reader(void *_count)
                if (caa_unlikely(rduration))
                        loop_sleep(rduration);
                rcu_read_unlock();
-               nr_reads++;
+               URCU_TLS(nr_reads)++;
                if (caa_unlikely(!test_duration_read()))
                        break;
        }
@@ -253,7 +254,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);
@@ -287,7 +288,7 @@ void *thr_writer(void *_count)
                        old->a = 0;
                test_array_free(old);
                rcu_copy_mutex_unlock();
-               nr_writes++;
+               URCU_TLS(nr_writes)++;
                if (caa_unlikely(!test_duration_write()))
                        break;
                if (caa_unlikely(wdelay))
@@ -296,7 +297,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);
 }
 
index 42d70c26ce8b15ef0ae074e83ca3c9632bc0dc00..31e22e511b96d5a61a45699a45225f35f3b6301a 100644 (file)
@@ -35,6 +35,7 @@
 #include <errno.h>
 
 #include <urcu/arch.h>
+#include <urcu/tls-compat.h>
 
 #ifdef __linux__
 #include <syscall.h>
@@ -154,8 +155,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;
@@ -242,14 +243,14 @@ void *thr_reader(void *_count)
                if (caa_unlikely(rduration))
                        loop_sleep(rduration);
                rcu_read_unlock();
-               nr_reads++;
+               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);
@@ -284,7 +285,7 @@ void *thr_writer(void *_count)
                        old->a = 0;
                test_array_free(old);
                rcu_copy_mutex_unlock();
-               nr_writes++;
+               URCU_TLS(nr_writes)++;
                if (caa_unlikely(!test_duration_write()))
                        break;
                if (caa_unlikely(wdelay))
@@ -293,7 +294,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);
 }
 
index 857913f83413e89722ce17f9b00182dc1254bea1..41caeb0995d1d19cfc6bab50d2179c5e2399d576 100644 (file)
@@ -35,6 +35,7 @@
 #include <errno.h>
 
 #include <urcu/arch.h>
+#include <urcu/tls-compat.h>
 
 #ifdef __linux__
 #include <syscall.h>
@@ -154,8 +155,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;
@@ -242,14 +243,14 @@ void *thr_reader(void *_count)
                if (caa_unlikely(rduration))
                        loop_sleep(rduration);
                rcu_read_unlock();
-               nr_reads++;
+               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);
@@ -283,7 +284,7 @@ void *thr_writer(void *_count)
                        old->a = 0;
                test_array_free(old);
                rcu_copy_mutex_unlock();
-               nr_writes++;
+               URCU_TLS(nr_writes)++;
                if (caa_unlikely(!test_duration_write()))
                        break;
                if (caa_unlikely(wdelay))
@@ -292,7 +293,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);
 }
 
index 1575e9c3523a45e07d96e4eae59af99acad54d63..cd9780b6f02f0b44d6f08e5ce5961590ebcde04a 100644 (file)
@@ -35,6 +35,7 @@
 #include <errno.h>
 
 #include <urcu/arch.h>
+#include <urcu/tls-compat.h>
 
 #ifdef __linux__
 #include <syscall.h>
@@ -155,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;
@@ -213,14 +214,14 @@ void *thr_reader(void *_count)
                if (caa_unlikely(rduration))
                        loop_sleep(rduration);
                rcu_read_unlock();
-               nr_reads++;
+               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);
@@ -271,7 +272,7 @@ 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++;
+               URCU_TLS(nr_writes)++;
                if (caa_unlikely(!test_duration_write()))
                        break;
                if (caa_unlikely(wdelay))
@@ -282,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);
 }
 
index 21c5d5608d37e79eba0d21b3261ee908ac12d366..3a425068e8db00f8ab27651fe48d185c15930125 100644 (file)
@@ -35,6 +35,7 @@
 #include <errno.h>
 
 #include <urcu/arch.h>
+#include <urcu/tls-compat.h>
 
 #ifdef __linux__
 #include <syscall.h>
@@ -163,8 +164,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;
@@ -221,14 +222,14 @@ void *thr_reader(void *_count)
                if (caa_unlikely(rduration))
                        loop_sleep(rduration);
                rcu_read_unlock();
-               nr_reads++;
+               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);
@@ -294,7 +295,7 @@ void *thr_writer(void *data)
                if (caa_unlikely(wduration))
                        loop_sleep(wduration);
                rcu_gc_reclaim(wtidx, old);
-               nr_writes++;
+               URCU_TLS(nr_writes)++;
                if (caa_unlikely(!test_duration_write()))
                        break;
                if (caa_unlikely(wdelay))
@@ -303,7 +304,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);
 }
 
index 2223413c8067506ba1441ea91b3298da0340c2e2..5710de08135f8e0f58be45bfec59cca94636031e 100644 (file)
@@ -82,13 +82,13 @@ int (*get_populate_hash_cb(void))(void)
        return test_hash_cb[test_choice].populate_hash;
 }
 
-unsigned int __thread rand_lookup;
-unsigned long __thread nr_add;
-unsigned long __thread nr_addexist;
-unsigned long __thread nr_del;
-unsigned long __thread nr_delnoent;
-unsigned long __thread lookup_fail;
-unsigned long __thread lookup_ok;
+DEFINE_URCU_TLS(unsigned int, rand_lookup);
+DEFINE_URCU_TLS(unsigned long, nr_add);
+DEFINE_URCU_TLS(unsigned long, nr_addexist);
+DEFINE_URCU_TLS(unsigned long, nr_del);
+DEFINE_URCU_TLS(unsigned long, nr_delnoent);
+DEFINE_URCU_TLS(unsigned long, lookup_fail);
+DEFINE_URCU_TLS(unsigned long, lookup_ok);
 
 struct cds_lfht *test_ht;
 
@@ -126,8 +126,8 @@ int use_affinity = 0;
 
 pthread_mutex_t affinity_mutex = PTHREAD_MUTEX_INITIALIZER;
 
-unsigned long long __thread nr_writes;
-unsigned long long __thread nr_reads;
+DEFINE_URCU_TLS(unsigned long long, nr_writes);
+DEFINE_URCU_TLS(unsigned long long, nr_reads);
 
 unsigned int nr_readers;
 unsigned int nr_writers;
index 083e71c3185214b7f81dd607a5705217bd2705bb..fe13c36ad192c890fda33a21b049daaa91bee3e4 100644 (file)
@@ -37,6 +37,8 @@
 #include <errno.h>
 #include <signal.h>
 
+#include <urcu/tls-compat.h>
+
 #ifdef __linux__
 #include <syscall.h>
 #endif
@@ -102,13 +104,13 @@ struct wr_count {
        unsigned long remove;
 };
 
-extern unsigned int __thread rand_lookup;
-extern unsigned long __thread nr_add;
-extern unsigned long __thread nr_addexist;
-extern unsigned long __thread nr_del;
-extern unsigned long __thread nr_delnoent;
-extern unsigned long __thread lookup_fail;
-extern unsigned long __thread lookup_ok;
+extern DECLARE_URCU_TLS(unsigned int, rand_lookup);
+extern DECLARE_URCU_TLS(unsigned long, nr_add);
+extern DECLARE_URCU_TLS(unsigned long, nr_addexist);
+extern DECLARE_URCU_TLS(unsigned long, nr_del);
+extern DECLARE_URCU_TLS(unsigned long, nr_delnoent);
+extern DECLARE_URCU_TLS(unsigned long, lookup_fail);
+extern DECLARE_URCU_TLS(unsigned long, lookup_ok);
 
 extern struct cds_lfht *test_ht;
 
@@ -214,8 +216,8 @@ static inline int test_duration_read(void)
        return !test_stop;
 }
 
-extern unsigned long long __thread nr_writes;
-extern unsigned long long __thread nr_reads;
+extern DECLARE_URCU_TLS(unsigned long long, nr_writes);
+extern DECLARE_URCU_TLS(unsigned long long, nr_reads);
 
 extern unsigned int nr_readers;
 extern unsigned int nr_writers;
index 73103444b6addc1ea90d3f9d8843f86fcefead39..a789236ecb0c67f875d1f8c0d17cbb28d429d7d4 100644 (file)
@@ -80,7 +80,7 @@ void *test_hash_rw_thr_reader(void *_count)
        for (;;) {
                rcu_read_lock();
                cds_lfht_test_lookup(test_ht,
-                       (void *)(((unsigned long) rand_r(&rand_lookup) % lookup_pool_size) + lookup_pool_offset),
+                       (void *)(((unsigned long) rand_r(&URCU_TLS(rand_lookup)) % lookup_pool_size) + lookup_pool_offset),
                        sizeof(void *), &iter);
                node = cds_lfht_iter_get_test_node(&iter);
                if (node == NULL) {
@@ -88,28 +88,29 @@ void *test_hash_rw_thr_reader(void *_count)
                                printf("[ERROR] Lookup cannot find initial node.\n");
                                exit(-1);
                        }
-                       lookup_fail++;
+                       URCU_TLS(lookup_fail)++;
                } else {
-                       lookup_ok++;
+                       URCU_TLS(lookup_ok)++;
                }
                debug_yield_read();
                if (caa_unlikely(rduration))
                        loop_sleep(rduration);
                rcu_read_unlock();
-               nr_reads++;
+               URCU_TLS(nr_reads)++;
                if (caa_unlikely(!test_duration_read()))
                        break;
-               if (caa_unlikely((nr_reads & ((1 << 10) - 1)) == 0))
+               if (caa_unlikely((URCU_TLS(nr_reads) & ((1 << 10) - 1)) == 0))
                        rcu_quiescent_state();
        }
 
        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());
        printf_verbose("readid : %lx, lookupfail %lu, lookupok %lu\n",
-                       pthread_self(), lookup_fail, lookup_ok);
+                       pthread_self(), URCU_TLS(lookup_fail),
+                       URCU_TLS(lookup_ok));
        return ((void*)1);
 
 }
@@ -136,10 +137,10 @@ void *test_hash_rw_thr_writer(void *_count)
 
        for (;;) {
                if ((addremove == AR_ADD || add_only)
-                               || (addremove == AR_RANDOM && rand_r(&rand_lookup) & 1)) {
+                               || (addremove == AR_RANDOM && rand_r(&URCU_TLS(rand_lookup)) & 1)) {
                        node = malloc(sizeof(struct lfht_test_node));
                        lfht_test_node_init(node,
-                               (void *)(((unsigned long) rand_r(&rand_lookup) % write_pool_size) + write_pool_offset),
+                               (void *)(((unsigned long) rand_r(&URCU_TLS(rand_lookup)) % write_pool_size) + write_pool_offset),
                                sizeof(void *));
                        rcu_read_lock();
                        if (add_unique) {
@@ -159,36 +160,36 @@ void *test_hash_rw_thr_writer(void *_count)
                        rcu_read_unlock();
                        if (add_unique && ret_node != &node->node) {
                                free(node);
-                               nr_addexist++;
+                               URCU_TLS(nr_addexist)++;
                        } else {
                                if (add_replace && ret_node) {
                                        call_rcu(&to_test_node(ret_node)->head,
                                                        free_node_cb);
-                                       nr_addexist++;
+                                       URCU_TLS(nr_addexist)++;
                                } else {
-                                       nr_add++;
+                                       URCU_TLS(nr_add)++;
                                }
                        }
                } else {
                        /* May delete */
                        rcu_read_lock();
                        cds_lfht_test_lookup(test_ht,
-                               (void *)(((unsigned long) rand_r(&rand_lookup) % write_pool_size) + write_pool_offset),
+                               (void *)(((unsigned long) rand_r(&URCU_TLS(rand_lookup)) % write_pool_size) + write_pool_offset),
                                sizeof(void *), &iter);
                        ret = cds_lfht_del(test_ht, cds_lfht_iter_get_node(&iter));
                        rcu_read_unlock();
                        if (ret == 0) {
                                node = cds_lfht_iter_get_test_node(&iter);
                                call_rcu(&node->head, free_node_cb);
-                               nr_del++;
+                               URCU_TLS(nr_del)++;
                        } else
-                               nr_delnoent++;
+                               URCU_TLS(nr_delnoent)++;
                }
 #if 0
-               //if (nr_writes % 100000 == 0) {
-               if (nr_writes % 1000 == 0) {
+               //if (URCU_TLS(nr_writes) % 100000 == 0) {
+               if (URCU_TLS(nr_writes) % 1000 == 0) {
                        rcu_read_lock();
-                       if (rand_r(&rand_lookup) & 1) {
+                       if (rand_r(&URCU_TLS(rand_lookup)) & 1) {
                                ht_resize(test_ht, 1);
                        } else {
                                ht_resize(test_ht, -1);
@@ -196,12 +197,12 @@ void *test_hash_rw_thr_writer(void *_count)
                        rcu_read_unlock();
                }
 #endif //0
-               nr_writes++;
+               URCU_TLS(nr_writes)++;
                if (caa_unlikely(!test_duration_write()))
                        break;
                if (caa_unlikely(wdelay))
                        loop_sleep(wdelay);
-               if (caa_unlikely((nr_writes & ((1 << 10) - 1)) == 0))
+               if (caa_unlikely((URCU_TLS(nr_writes) & ((1 << 10) - 1)) == 0))
                        rcu_quiescent_state();
        }
 
@@ -210,12 +211,13 @@ void *test_hash_rw_thr_writer(void *_count)
        printf_verbose("thread_end %s, thread id : %lx, tid %lu\n",
                        "writer", pthread_self(), (unsigned long)gettid());
        printf_verbose("info id %lx: nr_add %lu, nr_addexist %lu, nr_del %lu, "
-                       "nr_delnoent %lu\n", pthread_self(), nr_add,
-                       nr_addexist, nr_del, nr_delnoent);
-       count->update_ops = nr_writes;
-       count->add = nr_add;
-       count->add_exist = nr_addexist;
-       count->remove = nr_del;
+                       "nr_delnoent %lu\n", pthread_self(), URCU_TLS(nr_add),
+                       URCU_TLS(nr_addexist), URCU_TLS(nr_del),
+                       URCU_TLS(nr_delnoent));
+       count->update_ops = URCU_TLS(nr_writes);
+       count->add = URCU_TLS(nr_add);
+       count->add_exist = URCU_TLS(nr_addexist);
+       count->remove = URCU_TLS(nr_del);
        return ((void*)2);
 }
 
@@ -235,10 +237,10 @@ int test_hash_rw_populate_hash(void)
 "larger random pool (-p option). This may take a while...\n", init_populate, init_pool_size);
        }
 
-       while (nr_add < init_populate) {
+       while (URCU_TLS(nr_add) < init_populate) {
                node = malloc(sizeof(struct lfht_test_node));
                lfht_test_node_init(node,
-                       (void *)(((unsigned long) rand_r(&rand_lookup) % init_pool_size) + init_pool_offset),
+                       (void *)(((unsigned long) rand_r(&URCU_TLS(rand_lookup)) % init_pool_size) + init_pool_offset),
                        sizeof(void *));
                rcu_read_lock();
                if (add_unique) {
@@ -258,16 +260,16 @@ int test_hash_rw_populate_hash(void)
                rcu_read_unlock();
                if (add_unique && ret_node != &node->node) {
                        free(node);
-                       nr_addexist++;
+                       URCU_TLS(nr_addexist)++;
                } else {
                        if (add_replace && ret_node) {
                                call_rcu(&to_test_node(ret_node)->head, free_node_cb);
-                               nr_addexist++;
+                               URCU_TLS(nr_addexist)++;
                        } else {
-                               nr_add++;
+                               URCU_TLS(nr_add)++;
                        }
                }
-               nr_writes++;
+               URCU_TLS(nr_writes)++;
        }
        return 0;
 }
index c934feb72c62c82e73c6dff66e2154061c7f89f1..610f479080e257e3460651a15281f53e33e4ba07 100644 (file)
@@ -98,20 +98,21 @@ void *test_hash_unique_thr_reader(void *_count)
                debug_yield_read();
                if (caa_unlikely(rduration))
                        loop_sleep(rduration);
-               nr_reads++;
+               URCU_TLS(nr_reads)++;
                if (caa_unlikely(!test_duration_read()))
                        break;
-               if (caa_unlikely((nr_reads & ((1 << 10) - 1)) == 0))
+               if (caa_unlikely((URCU_TLS(nr_reads) & ((1 << 10) - 1)) == 0))
                        rcu_quiescent_state();
        }
 
        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());
        printf_verbose("readid : %lx, lookupfail %lu, lookupok %lu\n",
-                       pthread_self(), lookup_fail, lookup_ok);
+                       pthread_self(), URCU_TLS(lookup_fail),
+                       URCU_TLS(lookup_ok));
        return ((void*)1);
 
 }
@@ -142,13 +143,13 @@ void *test_hash_unique_thr_writer(void *_count)
                 * add unique/add replace with new node key from range.
                 */
                if (1 || (addremove == AR_ADD || add_only)
-                               || (addremove == AR_RANDOM && rand_r(&rand_lookup) & 1)) {
+                               || (addremove == AR_RANDOM && rand_r(&URCU_TLS(rand_lookup)) & 1)) {
                        node = malloc(sizeof(struct lfht_test_node));
                        lfht_test_node_init(node,
-                               (void *)(((unsigned long) rand_r(&rand_lookup) % write_pool_size) + write_pool_offset),
+                               (void *)(((unsigned long) rand_r(&URCU_TLS(rand_lookup)) % write_pool_size) + write_pool_offset),
                                sizeof(void *));
                        rcu_read_lock();
-                       loc_add_unique = rand_r(&rand_lookup) & 1;
+                       loc_add_unique = rand_r(&URCU_TLS(rand_lookup)) & 1;
                        if (loc_add_unique) {
                                ret_node = cds_lfht_add_unique(test_ht,
                                        test_hash(node->key, node->key_len, TEST_HASH_SEED),
@@ -168,39 +169,39 @@ void *test_hash_unique_thr_writer(void *_count)
                        if (loc_add_unique) {
                                if (ret_node != &node->node) {
                                        free(node);
-                                       nr_addexist++;
+                                       URCU_TLS(nr_addexist)++;
                                } else {
-                                       nr_add++;
+                                       URCU_TLS(nr_add)++;
                                }
                        } else {
                                if (ret_node) {
                                        call_rcu(&to_test_node(ret_node)->head,
                                                        free_node_cb);
-                                       nr_addexist++;
+                                       URCU_TLS(nr_addexist)++;
                                } else {
-                                       nr_add++;
+                                       URCU_TLS(nr_add)++;
                                }
                        }
                } else {
                        /* May delete */
                        rcu_read_lock();
                        cds_lfht_test_lookup(test_ht,
-                               (void *)(((unsigned long) rand_r(&rand_lookup) % write_pool_size) + write_pool_offset),
+                               (void *)(((unsigned long) rand_r(&URCU_TLS(rand_lookup)) % write_pool_size) + write_pool_offset),
                                sizeof(void *), &iter);
                        ret = cds_lfht_del(test_ht, cds_lfht_iter_get_node(&iter));
                        rcu_read_unlock();
                        if (ret == 0) {
                                node = cds_lfht_iter_get_test_node(&iter);
                                call_rcu(&node->head, free_node_cb);
-                               nr_del++;
+                               URCU_TLS(nr_del)++;
                        } else
-                               nr_delnoent++;
+                               URCU_TLS(nr_delnoent)++;
                }
 #if 0
-               //if (nr_writes % 100000 == 0) {
-               if (nr_writes % 1000 == 0) {
+               //if (URCU_TLS(nr_writes) % 100000 == 0) {
+               if (URCU_TLS(nr_writes) % 1000 == 0) {
                        rcu_read_lock();
-                       if (rand_r(&rand_lookup) & 1) {
+                       if (rand_r(&URCU_TLS(rand_lookup)) & 1) {
                                ht_resize(test_ht, 1);
                        } else {
                                ht_resize(test_ht, -1);
@@ -208,12 +209,12 @@ void *test_hash_unique_thr_writer(void *_count)
                        rcu_read_unlock();
                }
 #endif //0
-               nr_writes++;
+               URCU_TLS(nr_writes)++;
                if (caa_unlikely(!test_duration_write()))
                        break;
                if (caa_unlikely(wdelay))
                        loop_sleep(wdelay);
-               if (caa_unlikely((nr_writes & ((1 << 10) - 1)) == 0))
+               if (caa_unlikely((URCU_TLS(nr_writes) & ((1 << 10) - 1)) == 0))
                        rcu_quiescent_state();
        }
 
@@ -222,12 +223,13 @@ void *test_hash_unique_thr_writer(void *_count)
        printf_verbose("thread_end %s, thread id : %lx, tid %lu\n",
                        "writer", pthread_self(), (unsigned long)gettid());
        printf_verbose("info id %lx: nr_add %lu, nr_addexist %lu, nr_del %lu, "
-                       "nr_delnoent %lu\n", pthread_self(), nr_add,
-                       nr_addexist, nr_del, nr_delnoent);
-       count->update_ops = nr_writes;
-       count->add = nr_add;
-       count->add_exist = nr_addexist;
-       count->remove = nr_del;
+                       "nr_delnoent %lu\n", pthread_self(), URCU_TLS(nr_add),
+                       URCU_TLS(nr_addexist), URCU_TLS(nr_del),
+                       URCU_TLS(nr_delnoent));
+       count->update_ops = URCU_TLS(nr_writes);
+       count->add = URCU_TLS(nr_add);
+       count->add_exist = URCU_TLS(nr_addexist);
+       count->remove = URCU_TLS(nr_del);
        return ((void*)2);
 }
 
@@ -247,10 +249,10 @@ int test_hash_unique_populate_hash(void)
 "larger random pool (-p option). This may take a while...\n", init_populate, init_pool_size);
        }
 
-       while (nr_add < init_populate) {
+       while (URCU_TLS(nr_add) < init_populate) {
                node = malloc(sizeof(struct lfht_test_node));
                lfht_test_node_init(node,
-                       (void *)(((unsigned long) rand_r(&rand_lookup) % init_pool_size) + init_pool_offset),
+                       (void *)(((unsigned long) rand_r(&URCU_TLS(rand_lookup)) % init_pool_size) + init_pool_offset),
                        sizeof(void *));
                rcu_read_lock();
                ret_node = cds_lfht_add_replace(test_ht,
@@ -259,11 +261,11 @@ int test_hash_unique_populate_hash(void)
                rcu_read_unlock();
                if (ret_node) {
                        call_rcu(&to_test_node(ret_node)->head, free_node_cb);
-                       nr_addexist++;
+                       URCU_TLS(nr_addexist)++;
                } else {
-                       nr_add++;
+                       URCU_TLS(nr_add)++;
                }
-               nr_writes++;
+               URCU_TLS(nr_writes)++;
        }
        return 0;
 }
index 01a2781530741de5fa944959f00e98ddf2ec6dda..66ddd410c6d7d80c26bd35bf95e425fbfaf611ae 100644 (file)
@@ -38,6 +38,7 @@
 #include <errno.h>
 
 #include <urcu/arch.h>
+#include <urcu/tls-compat.h>
 
 #ifdef __linux__
 #include <syscall.h>
@@ -148,11 +149,11 @@ static int test_duration_enqueue(void)
        return !test_stop;
 }
 
-static unsigned long long __thread nr_dequeues;
-static unsigned long long __thread nr_enqueues;
+static DEFINE_URCU_TLS(unsigned long long, nr_dequeues);
+static DEFINE_URCU_TLS(unsigned long long, nr_enqueues);
 
-static unsigned long long __thread nr_successful_dequeues;
-static unsigned long long __thread nr_successful_enqueues;
+static DEFINE_URCU_TLS(unsigned long long, nr_successful_dequeues);
+static DEFINE_URCU_TLS(unsigned long long, nr_successful_enqueues);
 
 static unsigned int nr_enqueuers;
 static unsigned int nr_dequeuers;
@@ -188,24 +189,24 @@ void *thr_enqueuer(void *_count)
                rcu_read_lock();
                cds_lfq_enqueue_rcu(&q, &node->list);
                rcu_read_unlock();
-               nr_successful_enqueues++;
+               URCU_TLS(nr_successful_enqueues)++;
 
                if (caa_unlikely(wdelay))
                        loop_sleep(wdelay);
 fail:
-               nr_enqueues++;
+               URCU_TLS(nr_enqueues)++;
                if (caa_unlikely(!test_duration_enqueue()))
                        break;
        }
 
        rcu_unregister_thread();
 
-       count[0] = nr_enqueues;
-       count[1] = nr_successful_enqueues;
+       count[0] = URCU_TLS(nr_enqueues);
+       count[1] = URCU_TLS(nr_successful_enqueues);
        printf_verbose("enqueuer thread_end, thread id : %lx, tid %lu, "
                       "enqueues %llu successful_enqueues %llu\n",
-                      pthread_self(), (unsigned long)gettid(), nr_enqueues,
-                      nr_successful_enqueues);
+                      pthread_self(), (unsigned long)gettid(),
+                      URCU_TLS(nr_enqueues), URCU_TLS(nr_successful_enqueues));
        return ((void*)1);
 
 }
@@ -251,10 +252,10 @@ void *thr_dequeuer(void *_count)
 
                if (node) {
                        call_rcu(&node->rcu, free_node_cb);
-                       nr_successful_dequeues++;
+                       URCU_TLS(nr_successful_dequeues)++;
                }
 
-               nr_dequeues++;
+               URCU_TLS(nr_dequeues)++;
                if (caa_unlikely(!test_duration_dequeue()))
                        break;
                if (caa_unlikely(rduration))
@@ -265,10 +266,10 @@ void *thr_dequeuer(void *_count)
        rcu_defer_unregister_thread();
        printf_verbose("dequeuer thread_end, thread id : %lx, tid %lu, "
                       "dequeues %llu, successful_dequeues %llu\n",
-                      pthread_self(), (unsigned long)gettid(), nr_dequeues,
-                      nr_successful_dequeues);
-       count[0] = nr_dequeues;
-       count[1] = nr_successful_dequeues;
+                      pthread_self(), (unsigned long)gettid(),
+                      URCU_TLS(nr_dequeues), URCU_TLS(nr_successful_dequeues));
+       count[0] = URCU_TLS(nr_dequeues);
+       count[1] = URCU_TLS(nr_successful_dequeues);
        return ((void*)2);
 }
 
index b48a35fe0f1c77ebaf9806cc03422ce8567e74ba..88bf65d09bd533bf19139a4028e68e990e43ea64 100644 (file)
@@ -38,6 +38,7 @@
 #include <errno.h>
 
 #include <urcu/arch.h>
+#include <urcu/tls-compat.h>
 
 #ifdef __linux__
 #include <syscall.h>
@@ -148,11 +149,11 @@ static int test_duration_enqueue(void)
        return !test_stop;
 }
 
-static unsigned long long __thread nr_dequeues;
-static unsigned long long __thread nr_enqueues;
+static DEFINE_URCU_TLS(unsigned long long, nr_dequeues);
+static DEFINE_URCU_TLS(unsigned long long, nr_enqueues);
 
-static unsigned long long __thread nr_successful_dequeues;
-static unsigned long long __thread nr_successful_enqueues;
+static DEFINE_URCU_TLS(unsigned long long, nr_successful_dequeues);
+static DEFINE_URCU_TLS(unsigned long long, nr_successful_enqueues);
 
 static unsigned int nr_enqueuers;
 static unsigned int nr_dequeuers;
@@ -187,24 +188,24 @@ void *thr_enqueuer(void *_count)
                cds_lfs_node_init_rcu(&node->list);
                /* No rcu read-side is needed for push */
                cds_lfs_push_rcu(&s, &node->list);
-               nr_successful_enqueues++;
+               URCU_TLS(nr_successful_enqueues)++;
 
                if (caa_unlikely(wdelay))
                        loop_sleep(wdelay);
 fail:
-               nr_enqueues++;
+               URCU_TLS(nr_enqueues)++;
                if (caa_unlikely(!test_duration_enqueue()))
                        break;
        }
 
        rcu_unregister_thread();
 
-       count[0] = nr_enqueues;
-       count[1] = nr_successful_enqueues;
+       count[0] = URCU_TLS(nr_enqueues);
+       count[1] = URCU_TLS(nr_successful_enqueues);
        printf_verbose("enqueuer thread_end, thread id : %lx, tid %lu, "
                       "enqueues %llu successful_enqueues %llu\n",
-                      pthread_self(), (unsigned long)gettid(), nr_enqueues,
-                      nr_successful_enqueues);
+                      pthread_self(), (unsigned long)gettid(),
+                      URCU_TLS(nr_enqueues), URCU_TLS(nr_successful_enqueues));
        return ((void*)1);
 
 }
@@ -249,9 +250,9 @@ void *thr_dequeuer(void *_count)
                rcu_read_unlock();
                if (node) {
                        call_rcu(&node->rcu, free_node_cb);
-                       nr_successful_dequeues++;
+                       URCU_TLS(nr_successful_dequeues)++;
                }
-               nr_dequeues++;
+               URCU_TLS(nr_dequeues)++;
                if (caa_unlikely(!test_duration_dequeue()))
                        break;
                if (caa_unlikely(rduration))
@@ -263,10 +264,10 @@ void *thr_dequeuer(void *_count)
 
        printf_verbose("dequeuer thread_end, thread id : %lx, tid %lu, "
                       "dequeues %llu, successful_dequeues %llu\n",
-                      pthread_self(), (unsigned long)gettid(), nr_dequeues,
-                      nr_successful_dequeues);
-       count[0] = nr_dequeues;
-       count[1] = nr_successful_dequeues;
+                      pthread_self(), (unsigned long)gettid(),
+                      URCU_TLS(nr_dequeues), URCU_TLS(nr_successful_dequeues));
+       count[0] = URCU_TLS(nr_dequeues);
+       count[1] = URCU_TLS(nr_successful_dequeues);
        return ((void*)2);
 }
 
index b986fd825fabc4d8663ab395f95d875631453133..421fb0739bd8f665d22f25bf9f04a607776ecbf2 100644 (file)
@@ -35,6 +35,7 @@
 #include <errno.h>
 
 #include <urcu/arch.h>
+#include <urcu/tls-compat.h>
 
 #ifdef __linux__
 #include <syscall.h>
@@ -153,8 +154,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;
@@ -241,9 +242,9 @@ void *thr_reader(void *_count)
                if (caa_unlikely(rduration))
                        loop_sleep(rduration);
                rcu_read_unlock();
-               nr_reads++;
+               URCU_TLS(nr_reads)++;
                /* QS each 1024 reads */
-               if (caa_unlikely((nr_reads & ((1 << 10) - 1)) == 0))
+               if (caa_unlikely((URCU_TLS(nr_reads) & ((1 << 10) - 1)) == 0))
                        rcu_quiescent_state();
                if (caa_unlikely(!test_duration_read()))
                        break;
@@ -255,7 +256,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);
@@ -290,7 +291,7 @@ void *thr_writer(void *_count)
                        old->a = 0;
                test_array_free(old);
                rcu_copy_mutex_unlock();
-               nr_writes++;
+               URCU_TLS(nr_writes)++;
                if (caa_unlikely(!test_duration_write()))
                        break;
                if (caa_unlikely(wdelay))
@@ -299,7 +300,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);
 }
 
index 9deb0aa2044c1e8ec34d3f8a3736f90668b2c828..561a475d30c178c907ec5a9402060b9b8db685a2 100644 (file)
@@ -35,6 +35,7 @@
 #include <errno.h>
 
 #include <urcu/arch.h>
+#include <urcu/tls-compat.h>
 
 #ifdef __linux__
 #include <syscall.h>
@@ -159,8 +160,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;
@@ -217,9 +218,9 @@ void *thr_reader(void *_count)
                if (caa_unlikely(rduration))
                        loop_sleep(rduration);
                _rcu_read_unlock();
-               nr_reads++;
+               URCU_TLS(nr_reads)++;
                /* QS each 1024 reads */
-               if (caa_unlikely((nr_reads & ((1 << 10) - 1)) == 0))
+               if (caa_unlikely((URCU_TLS(nr_reads) & ((1 << 10) - 1)) == 0))
                        _rcu_quiescent_state();
                if (caa_unlikely(!test_duration_read()))
                        break;
@@ -227,7 +228,7 @@ void *thr_reader(void *_count)
 
        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);
@@ -293,7 +294,7 @@ void *thr_writer(void *data)
                if (caa_unlikely(wduration))
                        loop_sleep(wduration);
                rcu_gc_reclaim(wtidx, old);
-               nr_writes++;
+               URCU_TLS(nr_writes)++;
                if (caa_unlikely(!test_duration_write()))
                        break;
                if (caa_unlikely(wdelay))
@@ -302,7 +303,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);
 }
 
index 83ec6359f2c40710dc9ceb05ef2f39cbbb45868c..75a9275e74f2d9a4ae42c2fd1e9fa4ce33751546 100644 (file)
@@ -38,6 +38,7 @@
 #include <errno.h>
 
 #include <urcu/arch.h>
+#include <urcu/tls-compat.h>
 
 #ifdef __linux__
 #include <syscall.h>
@@ -147,11 +148,11 @@ static int test_duration_enqueue(void)
        return !test_stop;
 }
 
-static unsigned long long __thread nr_dequeues;
-static unsigned long long __thread nr_enqueues;
+static DEFINE_URCU_TLS(unsigned long long, nr_dequeues);
+static DEFINE_URCU_TLS(unsigned long long, nr_enqueues);
 
-static unsigned long long __thread nr_successful_dequeues;
-static unsigned long long __thread nr_successful_enqueues;
+static DEFINE_URCU_TLS(unsigned long long, nr_successful_dequeues);
+static DEFINE_URCU_TLS(unsigned long long, nr_successful_enqueues);
 
 static unsigned int nr_enqueuers;
 static unsigned int nr_dequeuers;
@@ -178,22 +179,22 @@ void *thr_enqueuer(void *_count)
                        goto fail;
                cds_wfq_node_init(node);
                cds_wfq_enqueue(&q, node);
-               nr_successful_enqueues++;
+               URCU_TLS(nr_successful_enqueues)++;
 
                if (caa_unlikely(wdelay))
                        loop_sleep(wdelay);
 fail:
-               nr_enqueues++;
+               URCU_TLS(nr_enqueues)++;
                if (caa_unlikely(!test_duration_enqueue()))
                        break;
        }
 
-       count[0] = nr_enqueues;
-       count[1] = nr_successful_enqueues;
+       count[0] = URCU_TLS(nr_enqueues);
+       count[1] = URCU_TLS(nr_successful_enqueues);
        printf_verbose("enqueuer thread_end, thread id : %lx, tid %lu, "
                       "enqueues %llu successful_enqueues %llu\n",
-                      pthread_self(), (unsigned long)gettid(), nr_enqueues,
-                      nr_successful_enqueues);
+                      pthread_self(), (unsigned long)gettid(),
+                      URCU_TLS(nr_enqueues), URCU_TLS(nr_successful_enqueues));
        return ((void*)1);
 
 }
@@ -217,10 +218,10 @@ void *thr_dequeuer(void *_count)
 
                if (node) {
                        free(node);
-                       nr_successful_dequeues++;
+                       URCU_TLS(nr_successful_dequeues)++;
                }
 
-               nr_dequeues++;
+               URCU_TLS(nr_dequeues)++;
                if (caa_unlikely(!test_duration_dequeue()))
                        break;
                if (caa_unlikely(rduration))
@@ -229,10 +230,10 @@ void *thr_dequeuer(void *_count)
 
        printf_verbose("dequeuer thread_end, thread id : %lx, tid %lu, "
                       "dequeues %llu, successful_dequeues %llu\n",
-                      pthread_self(), (unsigned long)gettid(), nr_dequeues,
-                      nr_successful_dequeues);
-       count[0] = nr_dequeues;
-       count[1] = nr_successful_dequeues;
+                      pthread_self(), (unsigned long)gettid(),
+                      URCU_TLS(nr_dequeues), URCU_TLS(nr_successful_dequeues));
+       count[0] = URCU_TLS(nr_dequeues);
+       count[1] = URCU_TLS(nr_successful_dequeues);
        return ((void*)2);
 }
 
index 7746a1d17447e332c1e88b6cf18523c49c57f439..be099449a78c6845f2af1eaefc6bc18d0c8ff6df 100644 (file)
@@ -38,6 +38,7 @@
 #include <errno.h>
 
 #include <urcu/arch.h>
+#include <urcu/tls-compat.h>
 
 #ifdef __linux__
 #include <syscall.h>
@@ -147,11 +148,11 @@ static int test_duration_enqueue(void)
        return !test_stop;
 }
 
-static unsigned long long __thread nr_dequeues;
-static unsigned long long __thread nr_enqueues;
+static DEFINE_URCU_TLS(unsigned long long, nr_dequeues);
+static DEFINE_URCU_TLS(unsigned long long, nr_enqueues);
 
-static unsigned long long __thread nr_successful_dequeues;
-static unsigned long long __thread nr_successful_enqueues;
+static DEFINE_URCU_TLS(unsigned long long, nr_successful_dequeues);
+static DEFINE_URCU_TLS(unsigned long long, nr_successful_enqueues);
 
 static unsigned int nr_enqueuers;
 static unsigned int nr_dequeuers;
@@ -178,22 +179,22 @@ void *thr_enqueuer(void *_count)
                        goto fail;
                cds_wfs_node_init(node);
                cds_wfs_push(&s, node);
-               nr_successful_enqueues++;
+               URCU_TLS(nr_successful_enqueues)++;
 
                if (caa_unlikely(wdelay))
                        loop_sleep(wdelay);
 fail:
-               nr_enqueues++;
+               URCU_TLS(nr_enqueues)++;
                if (caa_unlikely(!test_duration_enqueue()))
                        break;
        }
 
-       count[0] = nr_enqueues;
-       count[1] = nr_successful_enqueues;
+       count[0] = URCU_TLS(nr_enqueues);
+       count[1] = URCU_TLS(nr_successful_enqueues);
        printf_verbose("enqueuer thread_end, thread id : %lx, tid %lu, "
                       "enqueues %llu successful_enqueues %llu\n",
-                      pthread_self(), (unsigned long)gettid(), nr_enqueues,
-                      nr_successful_enqueues);
+                      pthread_self(), (unsigned long)gettid(),
+                      URCU_TLS(nr_enqueues), URCU_TLS(nr_successful_enqueues));
        return ((void*)1);
 
 }
@@ -217,10 +218,10 @@ void *thr_dequeuer(void *_count)
 
                if (node) {
                        free(node);
-                       nr_successful_dequeues++;
+                       URCU_TLS(nr_successful_dequeues)++;
                }
 
-               nr_dequeues++;
+               URCU_TLS(nr_dequeues)++;
                if (caa_unlikely(!test_duration_dequeue()))
                        break;
                if (caa_unlikely(rduration))
@@ -229,10 +230,10 @@ void *thr_dequeuer(void *_count)
 
        printf_verbose("dequeuer thread_end, thread id : %lx, tid %lu, "
                       "dequeues %llu, successful_dequeues %llu\n",
-                      pthread_self(), (unsigned long)gettid(), nr_dequeues,
-                      nr_successful_dequeues);
-       count[0] = nr_dequeues;
-       count[1] = nr_successful_dequeues;
+                      pthread_self(), (unsigned long)gettid(),
+                      URCU_TLS(nr_dequeues), URCU_TLS(nr_successful_dequeues));
+       count[0] = URCU_TLS(nr_dequeues);
+       count[1] = URCU_TLS(nr_successful_dequeues);
        return ((void*)2);
 }
 
index 08b4b55d46b97a353f177fc38114a8f350ae43f5..bb657d7dc620833d6c7b19cbf0b21e20c3ea78f4 100644 (file)
--- a/urcu-bp.c
+++ b/urcu-bp.c
@@ -40,6 +40,7 @@
 #include "urcu/map/urcu-bp.h"
 #include "urcu/static/urcu-bp.h"
 #include "urcu-pointer.h"
+#include "urcu/tls-compat.h"
 
 /* Do not #define _LGPL_SOURCE to ensure we can emit the wrapper symbols */
 #undef _LGPL_SOURCE
@@ -94,7 +95,7 @@ static pthread_mutex_t rcu_gp_lock = PTHREAD_MUTEX_INITIALIZER;
 
 #ifdef DEBUG_YIELD
 unsigned int yield_active;
-unsigned int __thread rand_yield;
+DEFINE_URCU_TLS(unsigned int, rand_yield);
 #endif
 
 /*
@@ -109,7 +110,7 @@ long rcu_gp_ctr = RCU_GP_COUNT;
  * Pointer to registry elements. Written to only by each individual reader. Read
  * by both the reader and the writers.
  */
-struct rcu_reader __thread *rcu_reader;
+DEFINE_URCU_TLS(struct rcu_reader *, rcu_reader);
 
 static CDS_LIST_HEAD(registry);
 
@@ -322,7 +323,7 @@ static void add_thread(void)
        rcu_reader_reg->tid = pthread_self();
        assert(rcu_reader_reg->ctr == 0);
        cds_list_add(&rcu_reader_reg->node, &registry);
-       rcu_reader = rcu_reader_reg;
+       URCU_TLS(rcu_reader) = rcu_reader_reg;
 }
 
 /* Called with signals off and mutex locked */
@@ -363,7 +364,7 @@ void rcu_bp_register(void)
        /*
         * Check if a signal concurrently registered our thread since
         * the check in rcu_read_lock(). */
-       if (rcu_reader)
+       if (URCU_TLS(rcu_reader))
                goto end;
 
        mutex_lock(&rcu_gp_lock);
index 36e3cf4b93a5904b5fc1e3d0ee84eccd1cc3d9ea..8ed2ab384f81c0806d7c40a74430eb527ad825de 100644 (file)
@@ -40,6 +40,7 @@
 #include "urcu-pointer.h"
 #include "urcu/list.h"
 #include "urcu/futex.h"
+#include "urcu/tls-compat.h"
 
 /* Data structure that identifies a call_rcu thread. */
 
@@ -62,7 +63,7 @@ CDS_LIST_HEAD(call_rcu_data_list);
 
 /* Link a thread using call_rcu() to its call_rcu thread. */
 
-static __thread struct call_rcu_data *thread_call_rcu_data;
+static DEFINE_URCU_TLS(struct call_rcu_data *, thread_call_rcu_data);
 
 /* Guard call_rcu thread creation. */
 
@@ -232,7 +233,7 @@ static void *call_rcu_thread(void *arg)
         */
        rcu_register_thread();
 
-       thread_call_rcu_data = crdp;
+       URCU_TLS(thread_call_rcu_data) = crdp;
        if (!rt) {
                uatomic_dec(&crdp->futex);
                /* Decrement futex before reading call_rcu list */
@@ -470,8 +471,8 @@ struct call_rcu_data *get_call_rcu_data(void)
 {
        struct call_rcu_data *crd;
 
-       if (thread_call_rcu_data != NULL)
-               return thread_call_rcu_data;
+       if (URCU_TLS(thread_call_rcu_data) != NULL)
+               return URCU_TLS(thread_call_rcu_data);
 
        if (maxcpus > 0) {
                crd = get_cpu_call_rcu_data(sched_getcpu());
@@ -488,7 +489,7 @@ struct call_rcu_data *get_call_rcu_data(void)
 
 struct call_rcu_data *get_thread_call_rcu_data(void)
 {
-       return thread_call_rcu_data;
+       return URCU_TLS(thread_call_rcu_data);
 }
 
 /*
@@ -504,7 +505,7 @@ struct call_rcu_data *get_thread_call_rcu_data(void)
 
 void set_thread_call_rcu_data(struct call_rcu_data *crdp)
 {
-       thread_call_rcu_data = crdp;
+       URCU_TLS(thread_call_rcu_data) = crdp;
 }
 
 /*
@@ -746,7 +747,7 @@ void call_rcu_after_fork_child(void)
        maxcpus_reset();
        free(per_cpu_call_rcu_data);
        rcu_set_pointer(&per_cpu_call_rcu_data, NULL);
-       thread_call_rcu_data = NULL;
+       URCU_TLS(thread_call_rcu_data) = NULL;
 
        /* Dispose of all of the rest of the call_rcu_data structures. */
        cds_list_for_each_entry_safe(crdp, next, &call_rcu_data_list, list) {
index 4d1ca5e4e63085f4dbe24f7284361e9879e46e4b..f65e41086022f2613bdaf251611a378afb6e5a3d 100644 (file)
@@ -48,6 +48,7 @@
 #include <urcu/uatomic.h>
 #include <urcu/list.h>
 #include <urcu/system.h>
+#include <urcu/tls-compat.h>
 
 /*
  * Number of entries in the per-thread defer queue. Must be power of 2.
@@ -130,7 +131,7 @@ static int32_t defer_thread_stop;
  * Written to only by each individual deferer. Read by both the deferer and
  * the reclamation tread.
  */
-static struct defer_queue __thread defer_queue;
+static DEFINE_URCU_TLS(struct defer_queue, defer_queue);
 static CDS_LIST_HEAD(registry_defer);
 static pthread_t tid_defer;
 
@@ -245,12 +246,12 @@ static void _rcu_defer_barrier_thread(void)
 {
        unsigned long head, num_items;
 
-       head = defer_queue.head;
-       num_items = head - defer_queue.tail;
+       head = URCU_TLS(defer_queue).head;
+       num_items = head - URCU_TLS(defer_queue).tail;
        if (caa_unlikely(!num_items))
                return;
        synchronize_rcu();
-       rcu_defer_barrier_queue(&defer_queue, head);
+       rcu_defer_barrier_queue(&URCU_TLS(defer_queue), head);
 }
 
 void rcu_defer_barrier_thread(void)
@@ -311,8 +312,8 @@ void _defer_rcu(void (*fct)(void *p), void *p)
         * Head is only modified by ourself. Tail can be modified by reclamation
         * thread.
         */
-       head = defer_queue.head;
-       tail = CMM_LOAD_SHARED(defer_queue.tail);
+       head = URCU_TLS(defer_queue).head;
+       tail = CMM_LOAD_SHARED(URCU_TLS(defer_queue).tail);
 
        /*
         * If queue is full, or reached threshold. Empty queue ourself.
@@ -321,7 +322,7 @@ void _defer_rcu(void (*fct)(void *p), void *p)
        if (caa_unlikely(head - tail >= DEFER_QUEUE_SIZE - 2)) {
                assert(head - tail <= DEFER_QUEUE_SIZE);
                rcu_defer_barrier_thread();
-               assert(head - CMM_LOAD_SHARED(defer_queue.tail) == 0);
+               assert(head - CMM_LOAD_SHARED(URCU_TLS(defer_queue).tail) == 0);
        }
 
        /*
@@ -340,25 +341,25 @@ void _defer_rcu(void (*fct)(void *p), void *p)
         * Decode: see the comments before 'struct defer_queue'
         *         or the code in rcu_defer_barrier_queue().
         */
-       if (caa_unlikely(defer_queue.last_fct_in != fct
+       if (caa_unlikely(URCU_TLS(defer_queue).last_fct_in != fct
                        || DQ_IS_FCT_BIT(p)
                        || p == DQ_FCT_MARK)) {
-               defer_queue.last_fct_in = fct;
+               URCU_TLS(defer_queue).last_fct_in = fct;
                if (caa_unlikely(DQ_IS_FCT_BIT(fct) || fct == DQ_FCT_MARK)) {
-                       _CMM_STORE_SHARED(defer_queue.q[head++ & DEFER_QUEUE_MASK],
+                       _CMM_STORE_SHARED(URCU_TLS(defer_queue).q[head++ & DEFER_QUEUE_MASK],
                                      DQ_FCT_MARK);
-                       _CMM_STORE_SHARED(defer_queue.q[head++ & DEFER_QUEUE_MASK],
+                       _CMM_STORE_SHARED(URCU_TLS(defer_queue).q[head++ & DEFER_QUEUE_MASK],
                                      fct);
                } else {
                        DQ_SET_FCT_BIT(fct);
-                       _CMM_STORE_SHARED(defer_queue.q[head++ & DEFER_QUEUE_MASK],
+                       _CMM_STORE_SHARED(URCU_TLS(defer_queue).q[head++ & DEFER_QUEUE_MASK],
                                      fct);
                }
        }
-       _CMM_STORE_SHARED(defer_queue.q[head++ & DEFER_QUEUE_MASK], p);
+       _CMM_STORE_SHARED(URCU_TLS(defer_queue).q[head++ & DEFER_QUEUE_MASK], p);
        cmm_smp_wmb();  /* Publish new pointer before head */
                        /* Write q[] before head. */
-       CMM_STORE_SHARED(defer_queue.head, head);
+       CMM_STORE_SHARED(URCU_TLS(defer_queue).head, head);
        cmm_smp_mb();   /* Write queue head before read futex */
        /*
         * Wake-up any waiting defer thread.
@@ -422,16 +423,16 @@ int rcu_defer_register_thread(void)
 {
        int was_empty;
 
-       assert(defer_queue.last_head == 0);
-       assert(defer_queue.q == NULL);
-       defer_queue.q = malloc(sizeof(void *) * DEFER_QUEUE_SIZE);
-       if (!defer_queue.q)
+       assert(URCU_TLS(defer_queue).last_head == 0);
+       assert(URCU_TLS(defer_queue).q == NULL);
+       URCU_TLS(defer_queue).q = malloc(sizeof(void *) * DEFER_QUEUE_SIZE);
+       if (!URCU_TLS(defer_queue).q)
                return -ENOMEM;
 
        mutex_lock_defer(&defer_thread_mutex);
        mutex_lock_defer(&rcu_defer_mutex);
        was_empty = cds_list_empty(&registry_defer);
-       cds_list_add(&defer_queue.list, &registry_defer);
+       cds_list_add(&URCU_TLS(defer_queue).list, &registry_defer);
        mutex_unlock(&rcu_defer_mutex);
 
        if (was_empty)
@@ -446,10 +447,10 @@ void rcu_defer_unregister_thread(void)
 
        mutex_lock_defer(&defer_thread_mutex);
        mutex_lock_defer(&rcu_defer_mutex);
-       cds_list_del(&defer_queue.list);
+       cds_list_del(&URCU_TLS(defer_queue).list);
        _rcu_defer_barrier_thread();
-       free(defer_queue.q);
-       defer_queue.q = NULL;
+       free(URCU_TLS(defer_queue).q);
+       URCU_TLS(defer_queue).q = NULL;
        is_empty = cds_list_empty(&registry_defer);
        mutex_unlock(&rcu_defer_mutex);
 
index 745676e209d3ff44dc828507e43ca8c09f023e9c..b20d564c5f6799f3ac42d5e53fe4fc331a322cf7 100644 (file)
@@ -40,6 +40,7 @@
 #define BUILD_QSBR_LIB
 #include "urcu/static/urcu-qsbr.h"
 #include "urcu-pointer.h"
+#include "urcu/tls-compat.h"
 
 /* Do not #define _LGPL_SOURCE to ensure we can emit the wrapper symbols */
 #undef _LGPL_SOURCE
@@ -66,11 +67,11 @@ unsigned long rcu_gp_ctr = RCU_GP_ONLINE;
  * Written to only by each individual reader. Read by both the reader and the
  * writers.
  */
-struct rcu_reader __thread rcu_reader;
+DEFINE_URCU_TLS(struct rcu_reader, rcu_reader);
 
 #ifdef DEBUG_YIELD
 unsigned int yield_active;
-unsigned int __thread rand_yield;
+DEFINE_URCU_TLS(unsigned int, rand_yield);
 #endif
 
 static CDS_LIST_HEAD(registry);
@@ -139,7 +140,7 @@ static void update_counter_and_wait(void)
         * quiescent state. Failure to do so could result in the writer
         * waiting forever while new readers are always accessing data
         * (no progress). Enforce compiler-order of store to rcu_gp_ctr
-        * before load rcu_reader ctr.
+        * before load URCU_TLS(rcu_reader).ctr.
         */
        cmm_barrier();
 
@@ -206,7 +207,7 @@ void synchronize_rcu(void)
 {
        unsigned long was_online;
 
-       was_online = rcu_reader.ctr;
+       was_online = URCU_TLS(rcu_reader).ctr;
 
        /* All threads should read qparity before accessing data structure
         * where new ptr points to.  In the "then" case, rcu_thread_offline
@@ -236,7 +237,7 @@ void synchronize_rcu(void)
         * committing next rcu_gp_ctr update to memory. Failure to
         * do so could result in the writer waiting forever while new
         * readers are always accessing data (no progress).  Enforce
-        * compiler-order of load rcu_reader ctr before store to
+        * compiler-order of load URCU_TLS(rcu_reader).ctr before store to
         * rcu_gp_ctr.
         */
        cmm_barrier();
@@ -269,7 +270,7 @@ void synchronize_rcu(void)
 {
        unsigned long was_online;
 
-       was_online = rcu_reader.ctr;
+       was_online = URCU_TLS(rcu_reader).ctr;
 
        /*
         * Mark the writer thread offline to make sure we don't wait for
@@ -326,11 +327,11 @@ void rcu_thread_online(void)
 
 void rcu_register_thread(void)
 {
-       rcu_reader.tid = pthread_self();
-       assert(rcu_reader.ctr == 0);
+       URCU_TLS(rcu_reader).tid = pthread_self();
+       assert(URCU_TLS(rcu_reader).ctr == 0);
 
        mutex_lock(&rcu_gp_lock);
-       cds_list_add(&rcu_reader.node, &registry);
+       cds_list_add(&URCU_TLS(rcu_reader).node, &registry);
        mutex_unlock(&rcu_gp_lock);
        _rcu_thread_online();
 }
@@ -343,7 +344,7 @@ void rcu_unregister_thread(void)
         */
        _rcu_thread_offline();
        mutex_lock(&rcu_gp_lock);
-       cds_list_del(&rcu_reader.node);
+       cds_list_del(&URCU_TLS(rcu_reader).node);
        mutex_unlock(&rcu_gp_lock);
 }
 
diff --git a/urcu.c b/urcu.c
index 39486296c19036561d7862748274223513172545..5fb4db8229eb2f8c4ac4893d9684d1401ed6e42b 100644 (file)
--- a/urcu.c
+++ b/urcu.c
@@ -40,6 +40,7 @@
 #include "urcu/map/urcu.h"
 #include "urcu/static/urcu.h"
 #include "urcu-pointer.h"
+#include "urcu/tls-compat.h"
 
 /* Do not #define _LGPL_SOURCE to ensure we can emit the wrapper symbols */
 #undef _LGPL_SOURCE
@@ -94,11 +95,11 @@ unsigned long rcu_gp_ctr = RCU_GP_COUNT;
  * Written to only by each individual reader. Read by both the reader and the
  * writers.
  */
-struct rcu_reader __thread rcu_reader;
+DEFINE_URCU_TLS(struct rcu_reader, rcu_reader);
 
 #ifdef DEBUG_YIELD
 unsigned int yield_active;
-unsigned int __thread rand_yield;
+DEFINE_URCU_TLS(unsigned int, rand_yield);
 #endif
 
 static CDS_LIST_HEAD(registry);
@@ -120,9 +121,9 @@ static void mutex_lock(pthread_mutex_t *mutex)
                        perror("Error in pthread mutex lock");
                        exit(-1);
                }
-               if (CMM_LOAD_SHARED(rcu_reader.need_mb)) {
+               if (CMM_LOAD_SHARED(URCU_TLS(rcu_reader).need_mb)) {
                        cmm_smp_mb();
-                       _CMM_STORE_SHARED(rcu_reader.need_mb, 0);
+                       _CMM_STORE_SHARED(URCU_TLS(rcu_reader).need_mb, 0);
                        cmm_smp_mb();
                }
                poll(NULL,0,10);
@@ -245,7 +246,7 @@ void update_counter_and_wait(void)
        cmm_smp_mb();
 
        /*
-        * Wait for each thread rcu_reader.ctr count to become 0.
+        * Wait for each thread URCU_TLS(rcu_reader).ctr count to become 0.
         */
        for (;;) {
                wait_loops++;
@@ -277,7 +278,8 @@ void update_counter_and_wait(void)
 #else /* #ifndef HAS_INCOHERENT_CACHES */
                /*
                 * BUSY-LOOP. Force the reader thread to commit its
-                * rcu_reader.ctr update to memory if we wait for too long.
+                * URCU_TLS(rcu_reader).ctr update to memory if we wait
+                * for too long.
                 */
                if (cds_list_empty(&registry)) {
                        if (wait_loops == RCU_QS_ACTIVE_ATTEMPTS) {
@@ -328,7 +330,7 @@ void synchronize_rcu(void)
         * committing next rcu_gp_ctr update to memory. Failure to do so could
         * result in the writer waiting forever while new readers are always
         * accessing data (no progress).  Enforce compiler-order of load
-        * rcu_reader ctr before store to rcu_gp_ctr.
+        * URCU_TLS(rcu_reader).ctr before store to rcu_gp_ctr.
         */
        cmm_barrier();
 
@@ -368,20 +370,20 @@ void rcu_read_unlock(void)
 
 void rcu_register_thread(void)
 {
-       rcu_reader.tid = pthread_self();
-       assert(rcu_reader.need_mb == 0);
-       assert(!(rcu_reader.ctr & RCU_GP_CTR_NEST_MASK));
+       URCU_TLS(rcu_reader).tid = pthread_self();
+       assert(URCU_TLS(rcu_reader).need_mb == 0);
+       assert(!(URCU_TLS(rcu_reader).ctr & RCU_GP_CTR_NEST_MASK));
 
        mutex_lock(&rcu_gp_lock);
        rcu_init();     /* In case gcc does not support constructor attribute */
-       cds_list_add(&rcu_reader.node, &registry);
+       cds_list_add(&URCU_TLS(rcu_reader).node, &registry);
        mutex_unlock(&rcu_gp_lock);
 }
 
 void rcu_unregister_thread(void)
 {
        mutex_lock(&rcu_gp_lock);
-       cds_list_del(&rcu_reader.node);
+       cds_list_del(&URCU_TLS(rcu_reader).node);
        mutex_unlock(&rcu_gp_lock);
 }
 
@@ -405,7 +407,7 @@ static void sigrcu_handler(int signo, siginfo_t *siginfo, void *context)
         * executed on.
         */
        cmm_smp_mb();
-       _CMM_STORE_SHARED(rcu_reader.need_mb, 0);
+       _CMM_STORE_SHARED(URCU_TLS(rcu_reader).need_mb, 0);
        cmm_smp_mb();
 }
 
index 8d221637a2756890d718faf55d7ca0a5a4a5ac23..e7b2edaeed8ce07de045cdf767fcd1ffe96e17be 100644 (file)
@@ -38,6 +38,7 @@
 #include <urcu/system.h>
 #include <urcu/uatomic.h>
 #include <urcu/list.h>
+#include <urcu/tls-compat.h>
 
 /*
  * This code section can only be included in LGPL 2.1 compatible source code.
@@ -74,25 +75,25 @@ extern "C" {
 #define MAX_SLEEP 50
 
 extern unsigned int yield_active;
-extern unsigned int __thread rand_yield;
+extern DECLARE_URCU_TLS(unsigned int, rand_yield);
 
 static inline void debug_yield_read(void)
 {
        if (yield_active & YIELD_READ)
-               if (rand_r(&rand_yield) & 0x1)
-                       usleep(rand_r(&rand_yield) % MAX_SLEEP);
+               if (rand_r(&URCU_TLS(rand_yield)) & 0x1)
+                       usleep(rand_r(&URCU_TLS(rand_yield)) % MAX_SLEEP);
 }
 
 static inline void debug_yield_write(void)
 {
        if (yield_active & YIELD_WRITE)
-               if (rand_r(&rand_yield) & 0x1)
-                       usleep(rand_r(&rand_yield) % MAX_SLEEP);
+               if (rand_r(&URCU_TLS(rand_yield)) & 0x1)
+                       usleep(rand_r(&URCU_TLS(rand_yield)) % MAX_SLEEP);
 }
 
 static inline void debug_yield_init(void)
 {
-       rand_yield = time(NULL) ^ pthread_self();
+       URCU_TLS(rand_yield) = time(NULL) ^ pthread_self();
 }
 #else
 static inline void debug_yield_read(void)
@@ -144,7 +145,7 @@ struct rcu_reader {
  * Adds a pointer dereference on the read-side, but won't require to unregister
  * the reader thread.
  */
-extern struct rcu_reader __thread *rcu_reader;
+extern DECLARE_URCU_TLS(struct rcu_reader *, rcu_reader);
 
 static inline int rcu_old_gp_ongoing(long *value)
 {
@@ -166,24 +167,24 @@ static inline void _rcu_read_lock(void)
        long tmp;
 
        /* Check if registered */
-       if (caa_unlikely(!rcu_reader))
+       if (caa_unlikely(!URCU_TLS(rcu_reader)))
                rcu_bp_register();
 
        cmm_barrier();  /* Ensure the compiler does not reorder us with mutex */
-       tmp = rcu_reader->ctr;
+       tmp = URCU_TLS(rcu_reader)->ctr;
        /*
         * rcu_gp_ctr is
         *   RCU_GP_COUNT | (~RCU_GP_CTR_PHASE or RCU_GP_CTR_PHASE)
         */
        if (caa_likely(!(tmp & RCU_GP_CTR_NEST_MASK))) {
-               _CMM_STORE_SHARED(rcu_reader->ctr, _CMM_LOAD_SHARED(rcu_gp_ctr));
+               _CMM_STORE_SHARED(URCU_TLS(rcu_reader)->ctr, _CMM_LOAD_SHARED(rcu_gp_ctr));
                /*
                 * Set active readers count for outermost nesting level before
                 * accessing the pointer.
                 */
                cmm_smp_mb();
        } else {
-               _CMM_STORE_SHARED(rcu_reader->ctr, tmp + RCU_GP_COUNT);
+               _CMM_STORE_SHARED(URCU_TLS(rcu_reader)->ctr, tmp + RCU_GP_COUNT);
        }
 }
 
@@ -193,7 +194,7 @@ static inline void _rcu_read_unlock(void)
         * Finish using rcu before decrementing the pointer.
         */
        cmm_smp_mb();
-       _CMM_STORE_SHARED(rcu_reader->ctr, rcu_reader->ctr - RCU_GP_COUNT);
+       _CMM_STORE_SHARED(URCU_TLS(rcu_reader)->ctr, URCU_TLS(rcu_reader)->ctr - RCU_GP_COUNT);
        cmm_barrier();  /* Ensure the compiler does not reorder us with mutex */
 }
 
index 68bfc31f540ee07adbb0701251adac9ccb0434b5..22908a45f95c6a6c77988ab73acd8baaa97e7f15 100644 (file)
@@ -42,6 +42,7 @@
 #include <urcu/uatomic.h>
 #include <urcu/list.h>
 #include <urcu/futex.h>
+#include <urcu/tls-compat.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -74,25 +75,25 @@ extern "C" {
 #define MAX_SLEEP 50
 
 extern unsigned int yield_active;
-extern unsigned int __thread rand_yield;
+extern DECLARE_URCU_TLS(unsigned int, rand_yield);
 
 static inline void debug_yield_read(void)
 {
        if (yield_active & YIELD_READ)
-               if (rand_r(&rand_yield) & 0x1)
-                       usleep(rand_r(&rand_yield) % MAX_SLEEP);
+               if (rand_r(&URCU_TLS(rand_yield)) & 0x1)
+                       usleep(rand_r(&URCU_TLS(rand_yield)) % MAX_SLEEP);
 }
 
 static inline void debug_yield_write(void)
 {
        if (yield_active & YIELD_WRITE)
-               if (rand_r(&rand_yield) & 0x1)
-                       usleep(rand_r(&rand_yield) % MAX_SLEEP);
+               if (rand_r(&URCU_TLS(rand_yield)) & 0x1)
+                       usleep(rand_r(&URCU_TLS(rand_yield)) % MAX_SLEEP);
 }
 
 static inline void debug_yield_init(void)
 {
-       rand_yield = time(NULL) ^ pthread_self();
+       URCU_TLS(rand_yield) = time(NULL) ^ pthread_self();
 }
 #else
 static inline void debug_yield_read(void)
@@ -128,7 +129,7 @@ struct rcu_reader {
        pthread_t tid;
 };
 
-extern struct rcu_reader __thread rcu_reader;
+extern DECLARE_URCU_TLS(struct rcu_reader, rcu_reader);
 
 extern int32_t gp_futex;
 
@@ -137,8 +138,8 @@ extern int32_t gp_futex;
  */
 static inline void wake_up_gp(void)
 {
-       if (caa_unlikely(_CMM_LOAD_SHARED(rcu_reader.waiting))) {
-               _CMM_STORE_SHARED(rcu_reader.waiting, 0);
+       if (caa_unlikely(_CMM_LOAD_SHARED(URCU_TLS(rcu_reader).waiting))) {
+               _CMM_STORE_SHARED(URCU_TLS(rcu_reader).waiting, 0);
                cmm_smp_mb();
                if (uatomic_read(&gp_futex) != -1)
                        return;
@@ -158,7 +159,7 @@ static inline int rcu_gp_ongoing(unsigned long *ctr)
 
 static inline void _rcu_read_lock(void)
 {
-       rcu_assert(rcu_reader.ctr);
+       rcu_assert(URCU_TLS(rcu_reader).ctr);
 }
 
 static inline void _rcu_read_unlock(void)
@@ -168,8 +169,8 @@ static inline void _rcu_read_unlock(void)
 static inline void _rcu_quiescent_state(void)
 {
        cmm_smp_mb();
-       _CMM_STORE_SHARED(rcu_reader.ctr, _CMM_LOAD_SHARED(rcu_gp_ctr));
-       cmm_smp_mb();   /* write rcu_reader.ctr before read futex */
+       _CMM_STORE_SHARED(URCU_TLS(rcu_reader).ctr, _CMM_LOAD_SHARED(rcu_gp_ctr));
+       cmm_smp_mb();   /* write URCU_TLS(rcu_reader).ctr before read futex */
        wake_up_gp();
        cmm_smp_mb();
 }
@@ -177,8 +178,8 @@ static inline void _rcu_quiescent_state(void)
 static inline void _rcu_thread_offline(void)
 {
        cmm_smp_mb();
-       CMM_STORE_SHARED(rcu_reader.ctr, 0);
-       cmm_smp_mb();   /* write rcu_reader.ctr before read futex */
+       CMM_STORE_SHARED(URCU_TLS(rcu_reader).ctr, 0);
+       cmm_smp_mb();   /* write URCU_TLS(rcu_reader).ctr before read futex */
        wake_up_gp();
        cmm_barrier();  /* Ensure the compiler does not reorder us with mutex */
 }
@@ -186,7 +187,7 @@ static inline void _rcu_thread_offline(void)
 static inline void _rcu_thread_online(void)
 {
        cmm_barrier();  /* Ensure the compiler does not reorder us with mutex */
-       _CMM_STORE_SHARED(rcu_reader.ctr, CMM_LOAD_SHARED(rcu_gp_ctr));
+       _CMM_STORE_SHARED(URCU_TLS(rcu_reader).ctr, CMM_LOAD_SHARED(rcu_gp_ctr));
        cmm_smp_mb();
 }
 
index 7ae018596ec89c9bbcf56b22340d100f0998357b..f27f8b6b7a151fdbe3ddfbb78719a11fbb51e168 100644 (file)
@@ -40,6 +40,7 @@
 #include <urcu/uatomic.h>
 #include <urcu/list.h>
 #include <urcu/futex.h>
+#include <urcu/tls-compat.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -121,25 +122,25 @@ extern "C" {
 #endif
 
 extern unsigned int yield_active;
-extern unsigned int __thread rand_yield;
+extern DECLARE_URCU_TLS(unsigned int, rand_yield);
 
 static inline void debug_yield_read(void)
 {
        if (yield_active & YIELD_READ)
-               if (rand_r(&rand_yield) & 0x1)
-                       usleep(rand_r(&rand_yield) % MAX_SLEEP);
+               if (rand_r(&URCU_TLS(rand_yield)) & 0x1)
+                       usleep(rand_r(&URCU_TLS(rand_yield)) % MAX_SLEEP);
 }
 
 static inline void debug_yield_write(void)
 {
        if (yield_active & YIELD_WRITE)
-               if (rand_r(&rand_yield) & 0x1)
-                       usleep(rand_r(&rand_yield) % MAX_SLEEP);
+               if (rand_r(&URCU_TLS(rand_yield)) & 0x1)
+                       usleep(rand_r(&URCU_TLS(rand_yield)) % MAX_SLEEP);
 }
 
 static inline void debug_yield_init(void)
 {
-       rand_yield = time(NULL) ^ (unsigned long) pthread_self();
+       URCU_TLS(rand_yield) = time(NULL) ^ (unsigned long) pthread_self();
 }
 #else
 static inline void debug_yield_read(void)
@@ -222,7 +223,7 @@ struct rcu_reader {
        pthread_t tid;
 };
 
-extern struct rcu_reader __thread rcu_reader;
+extern DECLARE_URCU_TLS(struct rcu_reader, rcu_reader);
 
 extern int32_t gp_futex;
 
@@ -256,20 +257,20 @@ static inline void _rcu_read_lock(void)
        unsigned long tmp;
 
        cmm_barrier();  /* Ensure the compiler does not reorder us with mutex */
-       tmp = rcu_reader.ctr;
+       tmp = URCU_TLS(rcu_reader).ctr;
        /*
         * rcu_gp_ctr is
         *   RCU_GP_COUNT | (~RCU_GP_CTR_PHASE or RCU_GP_CTR_PHASE)
         */
        if (caa_likely(!(tmp & RCU_GP_CTR_NEST_MASK))) {
-               _CMM_STORE_SHARED(rcu_reader.ctr, _CMM_LOAD_SHARED(rcu_gp_ctr));
+               _CMM_STORE_SHARED(URCU_TLS(rcu_reader).ctr, _CMM_LOAD_SHARED(rcu_gp_ctr));
                /*
                 * Set active readers count for outermost nesting level before
                 * accessing the pointer. See smp_mb_master().
                 */
                smp_mb_slave(RCU_MB_GROUP);
        } else {
-               _CMM_STORE_SHARED(rcu_reader.ctr, tmp + RCU_GP_COUNT);
+               _CMM_STORE_SHARED(URCU_TLS(rcu_reader).ctr, tmp + RCU_GP_COUNT);
        }
 }
 
@@ -277,19 +278,19 @@ static inline void _rcu_read_unlock(void)
 {
        unsigned long tmp;
 
-       tmp = rcu_reader.ctr;
+       tmp = URCU_TLS(rcu_reader).ctr;
        /*
         * Finish using rcu before decrementing the pointer.
         * See smp_mb_master().
         */
        if (caa_likely((tmp & RCU_GP_CTR_NEST_MASK) == RCU_GP_COUNT)) {
                smp_mb_slave(RCU_MB_GROUP);
-               _CMM_STORE_SHARED(rcu_reader.ctr, rcu_reader.ctr - RCU_GP_COUNT);
-               /* write rcu_reader.ctr before read futex */
+               _CMM_STORE_SHARED(URCU_TLS(rcu_reader).ctr, URCU_TLS(rcu_reader).ctr - RCU_GP_COUNT);
+               /* write URCU_TLS(rcu_reader).ctr before read futex */
                smp_mb_slave(RCU_MB_GROUP);
                wake_up_gp();
        } else {
-               _CMM_STORE_SHARED(rcu_reader.ctr, rcu_reader.ctr - RCU_GP_COUNT);
+               _CMM_STORE_SHARED(URCU_TLS(rcu_reader).ctr, URCU_TLS(rcu_reader).ctr - RCU_GP_COUNT);
        }
        cmm_barrier();  /* Ensure the compiler does not reorder us with mutex */
 }
This page took 0.0643 seconds and 4 git commands to generate.