benchmark: Use uatomic for accessing global states
authorOlivier Dion <odion@efficios.com>
Fri, 31 Mar 2023 14:53:43 +0000 (10:53 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 14 Aug 2023 19:39:17 +0000 (15:39 -0400)
Global states accesses were protected via memory barriers. Use the
uatomic API with the CMM memory model so that TSAN can understand the
ordering imposed by the synchronization flags.

Change-Id: I1bf5702c5ac470f308c478effe39e424a3158060
Co-authored-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Olivier Dion <odion@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
23 files changed:
tests/benchmark/Makefile.am
tests/benchmark/common-states.c [new file with mode: 0644]
tests/benchmark/common-states.h [new file with mode: 0644]
tests/benchmark/test_mutex.c
tests/benchmark/test_perthreadlock.c
tests/benchmark/test_rwlock.c
tests/benchmark/test_urcu.c
tests/benchmark/test_urcu_assign.c
tests/benchmark/test_urcu_bp.c
tests/benchmark/test_urcu_defer.c
tests/benchmark/test_urcu_gc.c
tests/benchmark/test_urcu_hash.c
tests/benchmark/test_urcu_hash.h
tests/benchmark/test_urcu_hash_rw.c
tests/benchmark/test_urcu_hash_unique.c
tests/benchmark/test_urcu_lfq.c
tests/benchmark/test_urcu_lfs.c
tests/benchmark/test_urcu_lfs_rcu.c
tests/benchmark/test_urcu_qsbr.c
tests/benchmark/test_urcu_qsbr_gc.c
tests/benchmark/test_urcu_wfcq.c
tests/benchmark/test_urcu_wfq.c
tests/benchmark/test_urcu_wfs.c

index 382939b27f3bc0d1cc4ede5ec4d3d67f8d281ddd..97000929f4c187e4e8198a0dc8ac39a0bf50e913 100644 (file)
@@ -3,6 +3,7 @@
 # SPDX-License-Identifier: MIT
 
 AM_CPPFLAGS += -I$(top_srcdir)/src -I$(top_srcdir)/tests/common
+AM_CPPFLAGS += -include $(top_srcdir)/tests/benchmark/common-states.h
 
 TEST_EXTENSIONS = .tap
 TAP_LOG_DRIVER_FLAGS = --merge --comments
@@ -11,6 +12,8 @@ TAP_LOG_DRIVER = env AM_TAP_AWK='$(AWK)' \
        URCU_TESTS_BUILDDIR='$(abs_top_builddir)/tests' \
        $(SHELL) $(top_srcdir)/tests/utils/tap-driver.sh
 
+noinst_HEADERS = common-states.h
+
 SCRIPT_LIST = \
        runpaul-phase1.sh \
        runpaul-phase2.sh \
@@ -65,163 +68,163 @@ URCU_CDS_LIB=$(top_builddir)/src/liburcu-cds.la
 
 DEBUG_YIELD_LIB=$(builddir)/../common/libdebug-yield.la
 
-test_urcu_SOURCES = test_urcu.c
+test_urcu_SOURCES = test_urcu.c common-states.c
 test_urcu_LDADD = $(URCU_LIB)
 
-test_urcu_dynamic_link_SOURCES = test_urcu.c
+test_urcu_dynamic_link_SOURCES = test_urcu.c common-states.c
 test_urcu_dynamic_link_LDADD = $(URCU_LIB)
 test_urcu_dynamic_link_CFLAGS = -DDYNAMIC_LINK_TEST $(AM_CFLAGS)
 
-test_urcu_timing_SOURCES = test_urcu_timing.c
+test_urcu_timing_SOURCES = test_urcu_timing.c common-states.c
 test_urcu_timing_LDADD = $(URCU_LIB)
 
-test_urcu_yield_SOURCES = test_urcu.c
+test_urcu_yield_SOURCES = test_urcu.c common-states.c
 test_urcu_yield_LDADD = $(URCU_LIB) $(DEBUG_YIELD_LIB)
 test_urcu_yield_CFLAGS = -DDEBUG_YIELD $(AM_CFLAGS)
 
 
-test_urcu_qsbr_SOURCES = test_urcu_qsbr.c
+test_urcu_qsbr_SOURCES = test_urcu_qsbr.c common-states.c
 test_urcu_qsbr_LDADD = $(URCU_QSBR_LIB)
 
-test_urcu_qsbr_timing_SOURCES = test_urcu_qsbr_timing.c
+test_urcu_qsbr_timing_SOURCES = test_urcu_qsbr_timing.c common-states.c
 test_urcu_qsbr_timing_LDADD = $(URCU_QSBR_LIB)
 
 
-test_urcu_mb_SOURCES = test_urcu.c
+test_urcu_mb_SOURCES = test_urcu.c common-states.c
 test_urcu_mb_LDADD = $(URCU_MB_LIB)
 test_urcu_mb_CFLAGS = -DRCU_MB $(AM_CFLAGS)
 
 
-test_urcu_signal_SOURCES = test_urcu.c
+test_urcu_signal_SOURCES = test_urcu.c common-states.c
 test_urcu_signal_LDADD = $(URCU_SIGNAL_LIB)
 test_urcu_signal_CFLAGS = -DRCU_SIGNAL $(AM_CFLAGS)
 
-test_urcu_signal_dynamic_link_SOURCES = test_urcu.c
+test_urcu_signal_dynamic_link_SOURCES = test_urcu.c common-states.c
 test_urcu_signal_dynamic_link_LDADD = $(URCU_SIGNAL_LIB)
 test_urcu_signal_dynamic_link_CFLAGS = -DRCU_SIGNAL -DDYNAMIC_LINK_TEST \
                                        $(AM_CFLAGS)
 
-test_urcu_signal_timing_SOURCES = test_urcu_timing.c
+test_urcu_signal_timing_SOURCES = test_urcu_timing.c common-states.c
 test_urcu_signal_timing_LDADD = $(URCU_SIGNAL_LIB)
 test_urcu_signal_timing_CFLAGS= -DRCU_SIGNAL $(AM_CFLAGS)
 
-test_urcu_signal_yield_SOURCES = test_urcu.c
+test_urcu_signal_yield_SOURCES = test_urcu.c common-states.c
 test_urcu_signal_yield_LDADD = $(URCU_SIGNAL_LIB) $(DEBUG_YIELD_LIB)
 test_urcu_signal_yield_CFLAGS = -DRCU_SIGNAL -DDEBUG_YIELD $(AM_CFLAGS)
 
-test_rwlock_timing_SOURCES = test_rwlock_timing.c
+test_rwlock_timing_SOURCES = test_rwlock_timing.c common-states.c
 test_rwlock_timing_LDADD = $(URCU_SIGNAL_LIB)
 
-test_rwlock_SOURCES = test_rwlock.c
+test_rwlock_SOURCES = test_rwlock.c common-states.c
 test_rwlock_LDADD = $(URCU_SIGNAL_LIB)
 
-test_perthreadlock_timing_SOURCES = test_perthreadlock_timing.c
+test_perthreadlock_timing_SOURCES = test_perthreadlock_timing.c common-states.c
 test_perthreadlock_timing_LDADD = $(URCU_SIGNAL_LIB)
 
-test_perthreadlock_SOURCES = test_perthreadlock.c
+test_perthreadlock_SOURCES = test_perthreadlock.c common-states.c
 test_perthreadlock_LDADD = $(URCU_SIGNAL_LIB)
 
-test_mutex_SOURCES = test_mutex.c
+test_mutex_SOURCES = test_mutex.c common-states.c
 
-test_looplen_SOURCES = test_looplen.c
+test_looplen_SOURCES = test_looplen.c common-states.c
 
-test_urcu_gc_SOURCES = test_urcu_gc.c
+test_urcu_gc_SOURCES = test_urcu_gc.c common-states.c
 test_urcu_gc_LDADD = $(URCU_LIB)
 
-test_urcu_signal_gc_SOURCES = test_urcu_gc.c
+test_urcu_signal_gc_SOURCES = test_urcu_gc.c common-states.c
 test_urcu_signal_gc_LDADD = $(URCU_SIGNAL_LIB)
 test_urcu_signal_gc_CFLAGS = -DRCU_SIGNAL $(AM_CFLAGS)
 
-test_urcu_mb_gc_SOURCES = test_urcu_gc.c
+test_urcu_mb_gc_SOURCES = test_urcu_gc.c common-states.c
 test_urcu_mb_gc_LDADD = $(URCU_MB_LIB)
 test_urcu_mb_gc_CFLAGS = -DRCU_MB $(AM_CFLAGS)
 
-test_urcu_qsbr_gc_SOURCES = test_urcu_qsbr_gc.c
+test_urcu_qsbr_gc_SOURCES = test_urcu_qsbr_gc.c common-states.c
 test_urcu_qsbr_gc_LDADD = $(URCU_QSBR_LIB)
 
-test_urcu_qsbr_lgc_SOURCES = test_urcu_qsbr_gc.c
+test_urcu_qsbr_lgc_SOURCES = test_urcu_qsbr_gc.c common-states.c
 test_urcu_qsbr_lgc_LDADD = $(URCU_QSBR_LIB)
 test_urcu_qsbr_lgc_CFLAGS = -DTEST_LOCAL_GC $(AM_CFLAGS)
 
-test_urcu_lgc_SOURCES = test_urcu_gc.c
+test_urcu_lgc_SOURCES = test_urcu_gc.c common-states.c
 test_urcu_lgc_LDADD = $(URCU_LIB)
 test_urcu_lgc_CFLAGS = -DTEST_LOCAL_GC $(AM_CFLAGS)
 
-test_urcu_signal_lgc_SOURCES = test_urcu_gc.c
+test_urcu_signal_lgc_SOURCES = test_urcu_gc.c common-states.c
 test_urcu_signal_lgc_LDADD = $(URCU_SIGNAL_LIB)
 test_urcu_signal_lgc_CFLAGS = -DRCU_SIGNAL -DTEST_LOCAL_GC $(AM_CFLAGS)
 
-test_urcu_mb_lgc_SOURCES = test_urcu_gc.c
+test_urcu_mb_lgc_SOURCES = test_urcu_gc.c common-states.c
 test_urcu_mb_lgc_LDADD = $(URCU_MB_LIB)
 test_urcu_mb_lgc_CFLAGS = -DTEST_LOCAL_GC -DRCU_MB $(AM_CFLAGS)
 
-test_urcu_qsbr_dynamic_link_SOURCES = test_urcu_qsbr.c
+test_urcu_qsbr_dynamic_link_SOURCES = test_urcu_qsbr.c common-states.c
 test_urcu_qsbr_dynamic_link_LDADD = $(URCU_QSBR_LIB)
 test_urcu_qsbr_dynamic_link_CFLAGS = -DDYNAMIC_LINK_TEST $(AM_CFLAGS)
 
-test_urcu_defer_SOURCES = test_urcu_defer.c
+test_urcu_defer_SOURCES = test_urcu_defer.c common-states.c
 test_urcu_defer_LDADD = $(URCU_LIB)
 
 test_cycles_per_loop_SOURCES = test_cycles_per_loop.c
 
-test_urcu_assign_SOURCES = test_urcu_assign.c
+test_urcu_assign_SOURCES = test_urcu_assign.c common-states.c
 test_urcu_assign_LDADD = $(URCU_LIB)
 
-test_urcu_assign_dynamic_link_SOURCES = test_urcu_assign.c
+test_urcu_assign_dynamic_link_SOURCES = test_urcu_assign.c common-states.c
 test_urcu_assign_dynamic_link_LDADD = $(URCU_LIB)
 test_urcu_assign_dynamic_link_CFLAGS = -DDYNAMIC_LINK_TEST $(AM_CFLAGS)
 
-test_urcu_bp_SOURCES = test_urcu_bp.c
+test_urcu_bp_SOURCES = test_urcu_bp.c common-states.c
 test_urcu_bp_LDADD = $(URCU_BP_LIB)
 
-test_urcu_bp_dynamic_link_SOURCES = test_urcu_bp.c
+test_urcu_bp_dynamic_link_SOURCES = test_urcu_bp.c common-states.c
 test_urcu_bp_dynamic_link_LDADD = $(URCU_BP_LIB)
 test_urcu_bp_dynamic_link_CFLAGS = -DDYNAMIC_LINK_TEST $(AM_CFLAGS)
 
-test_urcu_lfq_SOURCES = test_urcu_lfq.c
+test_urcu_lfq_SOURCES = test_urcu_lfq.c common-states.c
 test_urcu_lfq_LDADD = $(URCU_LIB) $(URCU_CDS_LIB)
 
-test_urcu_lfq_dynlink_SOURCES = test_urcu_lfq.c
+test_urcu_lfq_dynlink_SOURCES = test_urcu_lfq.c common-states.c
 test_urcu_lfq_dynlink_CFLAGS = -DDYNAMIC_LINK_TEST $(AM_CFLAGS)
 test_urcu_lfq_dynlink_LDADD = $(URCU_LIB) $(URCU_CDS_LIB)
 
-test_urcu_wfq_SOURCES = test_urcu_wfq.c
+test_urcu_wfq_SOURCES = test_urcu_wfq.c common-states.c
 test_urcu_wfq_LDADD = $(URCU_COMMON_LIB)
 
-test_urcu_wfq_dynlink_SOURCES = test_urcu_wfq.c
+test_urcu_wfq_dynlink_SOURCES = test_urcu_wfq.c common-states.c
 test_urcu_wfq_dynlink_CFLAGS = -DDYNAMIC_LINK_TEST $(AM_CFLAGS)
 test_urcu_wfq_dynlink_LDADD = $(URCU_COMMON_LIB)
 
-test_urcu_wfcq_SOURCES = test_urcu_wfcq.c
+test_urcu_wfcq_SOURCES = test_urcu_wfcq.c common-states.c
 test_urcu_wfcq_LDADD = $(URCU_COMMON_LIB)
 
-test_urcu_wfcq_dynlink_SOURCES = test_urcu_wfcq.c
+test_urcu_wfcq_dynlink_SOURCES = test_urcu_wfcq.c common-states.c
 test_urcu_wfcq_dynlink_CFLAGS = -DDYNAMIC_LINK_TEST $(AM_CFLAGS)
 test_urcu_wfcq_dynlink_LDADD = $(URCU_COMMON_LIB)
 
-test_urcu_lfs_SOURCES = test_urcu_lfs.c
+test_urcu_lfs_SOURCES = test_urcu_lfs.c common-states.c
 test_urcu_lfs_LDADD = $(URCU_LIB) $(URCU_CDS_LIB)
 
-test_urcu_lfs_rcu_SOURCES = test_urcu_lfs_rcu.c
+test_urcu_lfs_rcu_SOURCES = test_urcu_lfs_rcu.c common-states.c
 test_urcu_lfs_rcu_LDADD = $(URCU_LIB) $(URCU_CDS_LIB)
 
-test_urcu_lfs_dynlink_SOURCES = test_urcu_lfs.c
+test_urcu_lfs_dynlink_SOURCES = test_urcu_lfs.c common-states.c
 test_urcu_lfs_dynlink_CFLAGS = -DDYNAMIC_LINK_TEST $(AM_CFLAGS)
 test_urcu_lfs_dynlink_LDADD = $(URCU_LIB) $(URCU_CDS_LIB)
 
-test_urcu_lfs_rcu_dynlink_SOURCES = test_urcu_lfs_rcu.c
+test_urcu_lfs_rcu_dynlink_SOURCES = test_urcu_lfs_rcu.c common-states.c
 test_urcu_lfs_rcu_dynlink_CFLAGS = -DDYNAMIC_LINK_TEST $(AM_CFLAGS)
 test_urcu_lfs_rcu_dynlink_LDADD = $(URCU_LIB) $(URCU_CDS_LIB)
 
-test_urcu_wfs_SOURCES = test_urcu_wfs.c
+test_urcu_wfs_SOURCES = test_urcu_wfs.c common-states.c
 test_urcu_wfs_LDADD = $(URCU_COMMON_LIB)
 
-test_urcu_wfs_dynlink_SOURCES = test_urcu_wfs.c
+test_urcu_wfs_dynlink_SOURCES = test_urcu_wfs.c common-states.c
 test_urcu_wfs_dynlink_CFLAGS = -DDYNAMIC_LINK_TEST $(AM_CFLAGS)
 test_urcu_wfs_dynlink_LDADD = $(URCU_COMMON_LIB)
 
 test_urcu_hash_SOURCES = test_urcu_hash.c test_urcu_hash.h \
-               test_urcu_hash_rw.c test_urcu_hash_unique.c
+               test_urcu_hash_rw.c test_urcu_hash_unique.c common-states.c
 test_urcu_hash_CFLAGS = -DRCU_QSBR $(AM_CFLAGS)
 test_urcu_hash_LDADD = $(URCU_QSBR_LIB) $(URCU_COMMON_LIB) $(URCU_CDS_LIB)
 
diff --git a/tests/benchmark/common-states.c b/tests/benchmark/common-states.c
new file mode 100644 (file)
index 0000000..6e70351
--- /dev/null
@@ -0,0 +1 @@
+volatile int _test_go = 0, _test_stop = 0;
diff --git a/tests/benchmark/common-states.h b/tests/benchmark/common-states.h
new file mode 100644 (file)
index 0000000..dfbbfe5
--- /dev/null
@@ -0,0 +1,51 @@
+/* Common states for benchmarks. */
+
+#include <unistd.h>
+
+#include <urcu/uatomic.h>
+
+extern volatile int _test_go, _test_stop;
+
+static inline void complete_sleep(unsigned int seconds)
+{
+       while (seconds != 0) {
+               seconds = sleep(seconds);
+       }
+}
+
+static inline void begin_test(void)
+{
+       uatomic_store(&_test_go, 1, CMM_RELEASE);
+}
+
+static inline void end_test(void)
+{
+       uatomic_store(&_test_stop, 1, CMM_RELAXED);
+}
+
+static inline void test_for(unsigned int duration)
+{
+       begin_test();
+       complete_sleep(duration);
+       end_test();
+}
+
+static inline void wait_until_go(void)
+{
+       while (!uatomic_load(&_test_go, CMM_ACQUIRE))
+       {
+       }
+}
+
+/*
+ * returns 0 if test should end.
+ */
+static inline int test_duration_write(void)
+{
+       return !uatomic_load(&_test_stop, CMM_RELAXED);
+}
+
+static inline int test_duration_read(void)
+{
+       return !uatomic_load(&_test_stop, CMM_RELAXED);
+}
index bbad448382de6b7925d21905b73db18b99b3fcd8..6254e15c4cf0dee0bbf50f826eb8d0e1b91d295f 100644 (file)
@@ -35,8 +35,6 @@ struct test_array {
 
 static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
 
-static volatile int test_go, test_stop;
-
 static unsigned long wdelay;
 
 static volatile struct test_array test_array = { 8 };
@@ -97,19 +95,6 @@ static void set_affinity(void)
 #endif /* HAVE_SCHED_SETAFFINITY */
 }
 
-/*
- * returns 0 if test should end.
- */
-static int test_duration_write(void)
-{
-       return !test_stop;
-}
-
-static int test_duration_read(void)
-{
-       return !test_stop;
-}
-
 static DEFINE_URCU_TLS(unsigned long long, nr_writes);
 static DEFINE_URCU_TLS(unsigned long long, nr_reads);
 
@@ -133,9 +118,7 @@ void *thr_reader(void *data)
 
        set_affinity();
 
-       while (!test_go)
-       {
-       }
+       wait_until_go();
 
        for (;;) {
                int v;
@@ -168,10 +151,7 @@ void *thr_writer(void *data)
 
        set_affinity();
 
-       while (!test_go)
-       {
-       }
-       cmm_smp_mb();
+       wait_until_go();
 
        for (;;) {
                pthread_mutex_lock(&lock);
@@ -311,13 +291,7 @@ int main(int argc, char **argv)
                        exit(1);
        }
 
-       cmm_smp_mb();
-
-       test_go = 1;
-
-       sleep(duration);
-
-       test_stop = 1;
+       test_for(duration);
 
        for (i_thr = 0; i_thr < nr_readers; i_thr++) {
                err = pthread_join(tid_reader[i_thr], &tret);
index bc7652f0c30578aca3eb042a140e123463c44acc..2cc50d1d13b296400bfea0b0afa2572e75c399dc 100644 (file)
@@ -39,8 +39,6 @@ struct per_thread_lock {
 
 static struct per_thread_lock *per_thread_lock;
 
-static volatile int test_go, test_stop;
-
 static unsigned long wdelay;
 
 static volatile struct test_array test_array = { 8 };
@@ -103,19 +101,6 @@ static void set_affinity(void)
 #endif /* HAVE_SCHED_SETAFFINITY */
 }
 
-/*
- * returns 0 if test should end.
- */
-static int test_duration_write(void)
-{
-       return !test_stop;
-}
-
-static int test_duration_read(void)
-{
-       return !test_stop;
-}
-
 static DEFINE_URCU_TLS(unsigned long long, nr_writes);
 static DEFINE_URCU_TLS(unsigned long long, nr_reads);
 
@@ -161,9 +146,7 @@ void *thr_reader(void *data)
 
        set_affinity();
 
-       while (!test_go)
-       {
-       }
+       wait_until_go();
 
        for (;;) {
                int v;
@@ -197,10 +180,7 @@ void *thr_writer(void *data)
 
        set_affinity();
 
-       while (!test_go)
-       {
-       }
-       cmm_smp_mb();
+       wait_until_go();
 
        for (;;) {
                for (tidx = 0; tidx < (long)nr_readers; tidx++) {
@@ -345,13 +325,7 @@ int main(int argc, char **argv)
                        exit(1);
        }
 
-       cmm_smp_mb();
-
-       test_go = 1;
-
-       sleep(duration);
-
-       test_stop = 1;
+       test_for(duration);
 
        for (i_thr = 0; i_thr < nr_readers; i_thr++) {
                err = pthread_join(tid_reader[i_thr], &tret);
index dbd0854543bf336e97938637f51a0d01c5478f1b..b275f78a51deb4f67afe134b63d1c0cff9b2545e 100644 (file)
@@ -39,8 +39,6 @@ struct test_array {
  */
 pthread_rwlock_t lock;
 
-static volatile int test_go, test_stop;
-
 static unsigned long wdelay;
 
 static volatile struct test_array test_array = { 8 };
@@ -102,19 +100,6 @@ static void set_affinity(void)
 #endif /* HAVE_SCHED_SETAFFINITY */
 }
 
-/*
- * returns 0 if test should end.
- */
-static int test_duration_write(void)
-{
-       return !test_stop;
-}
-
-static int test_duration_read(void)
-{
-       return !test_stop;
-}
-
 static DEFINE_URCU_TLS(unsigned long long, nr_writes);
 static DEFINE_URCU_TLS(unsigned long long, nr_reads);
 
@@ -133,9 +118,7 @@ void *thr_reader(void *_count)
 
        set_affinity();
 
-       while (!test_go)
-       {
-       }
+       wait_until_go();
 
        for (;;) {
                int a, ret;
@@ -180,10 +163,7 @@ void *thr_writer(void *_count)
 
        set_affinity();
 
-       while (!test_go)
-       {
-       }
-       cmm_smp_mb();
+       wait_until_go();
 
        for (;;) {
                int ret;
@@ -341,13 +321,7 @@ int main(int argc, char **argv)
                        exit(1);
        }
 
-       cmm_smp_mb();
-
-       test_go = 1;
-
-       sleep(duration);
-
-       test_stop = 1;
+       test_for(duration);
 
        for (i_thr = 0; i_thr < nr_readers; i_thr++) {
                err = pthread_join(tid_reader[i_thr], &tret);
index 8b19f229527dce1fc90e6502180277f26e45cf03..053993ae940349c7f0ae8a559bdf1f7180fd167a 100644 (file)
@@ -30,8 +30,6 @@
 #endif
 #include <urcu.h>
 
-static volatile int test_go, test_stop;
-
 static unsigned long wdelay;
 
 static int *test_rcu_pointer;
@@ -93,19 +91,6 @@ static void set_affinity(void)
 #endif /* HAVE_SCHED_SETAFFINITY */
 }
 
-/*
- * returns 0 if test should end.
- */
-static int test_duration_write(void)
-{
-       return !test_stop;
-}
-
-static int test_duration_read(void)
-{
-       return !test_stop;
-}
-
 static DEFINE_URCU_TLS(unsigned long long, nr_writes);
 static DEFINE_URCU_TLS(unsigned long long, nr_reads);
 
@@ -128,10 +113,7 @@ void *thr_reader(void *_count)
        rcu_register_thread();
        urcu_posix_assert(!rcu_read_ongoing());
 
-       while (!test_go)
-       {
-       }
-       cmm_smp_mb();
+       wait_until_go();
 
        for (;;) {
                rcu_read_lock();
@@ -172,10 +154,7 @@ void *thr_writer(void *_count)
 
        set_affinity();
 
-       while (!test_go)
-       {
-       }
-       cmm_smp_mb();
+       wait_until_go();
 
        for (;;) {
                new = malloc(sizeof(int));
@@ -323,13 +302,7 @@ int main(int argc, char **argv)
                        exit(1);
        }
 
-       cmm_smp_mb();
-
-       test_go = 1;
-
-       sleep(duration);
-
-       test_stop = 1;
+       test_for(duration);
 
        for (i_thr = 0; i_thr < nr_readers; i_thr++) {
                err = pthread_join(tid_reader[i_thr], &tret);
index 1272231d9fc02c666b3becacc440d30a15fafc31..d0272a7b2bf07939af4dce3643b31d736446b95c 100644 (file)
@@ -34,8 +34,6 @@ struct test_array {
        int a;
 };
 
-static volatile int test_go, test_stop;
-
 static unsigned long wdelay;
 
 static struct test_array *test_rcu_pointer;
@@ -97,19 +95,6 @@ static void set_affinity(void)
 #endif /* HAVE_SCHED_SETAFFINITY */
 }
 
-/*
- * returns 0 if test should end.
- */
-static int test_duration_write(void)
-{
-       return !test_stop;
-}
-
-static int test_duration_read(void)
-{
-       return !test_stop;
-}
-
 static DEFINE_URCU_TLS(unsigned long long, nr_writes);
 static DEFINE_URCU_TLS(unsigned long long, nr_reads);
 
@@ -187,10 +172,7 @@ void *thr_reader(void *_count)
 
        rcu_register_thread();
 
-       while (!test_go)
-       {
-       }
-       cmm_smp_mb();
+       wait_until_go();
 
        for (;;) {
                rcu_read_lock();
@@ -226,10 +208,7 @@ void *thr_writer(void *_count)
 
        set_affinity();
 
-       while (!test_go)
-       {
-       }
-       cmm_smp_mb();
+       wait_until_go();
 
        for (;;) {
                rcu_copy_mutex_lock();
@@ -380,13 +359,7 @@ int main(int argc, char **argv)
                        exit(1);
        }
 
-       cmm_smp_mb();
-
-       test_go = 1;
-
-       sleep(duration);
-
-       test_stop = 1;
+       test_for(duration);
 
        for (i_thr = 0; i_thr < nr_readers; i_thr++) {
                err = pthread_join(tid_reader[i_thr], &tret);
index a797c9daeee557276a9b9e88451c5728492c7df2..5da71320db3692c7159bcde0dd9937868c15ece9 100644 (file)
@@ -30,8 +30,6 @@
 #endif
 #include <urcu-bp.h>
 
-static volatile int test_go, test_stop;
-
 static unsigned long wdelay;
 
 static int *test_rcu_pointer;
@@ -93,19 +91,6 @@ static void set_affinity(void)
 #endif /* HAVE_SCHED_SETAFFINITY */
 }
 
-/*
- * returns 0 if test should end.
- */
-static int test_duration_write(void)
-{
-       return !test_stop;
-}
-
-static int test_duration_read(void)
-{
-       return !test_stop;
-}
-
 static DEFINE_URCU_TLS(unsigned long long, nr_writes);
 static DEFINE_URCU_TLS(unsigned long long, nr_reads);
 
@@ -128,10 +113,7 @@ void *thr_reader(void *_count)
        rcu_register_thread();
        urcu_posix_assert(!rcu_read_ongoing());
 
-       while (!test_go)
-       {
-       }
-       cmm_smp_mb();
+       wait_until_go();
 
        for (;;) {
                rcu_read_lock();
@@ -168,10 +150,7 @@ void *thr_writer(void *_count)
 
        set_affinity();
 
-       while (!test_go)
-       {
-       }
-       cmm_smp_mb();
+       wait_until_go();
 
        for (;;) {
                new = malloc(sizeof(int));
@@ -318,13 +297,7 @@ int main(int argc, char **argv)
                        exit(1);
        }
 
-       cmm_smp_mb();
-
-       test_go = 1;
-
-       sleep(duration);
-
-       test_stop = 1;
+       test_for(duration);
 
        for (i_thr = 0; i_thr < nr_readers; i_thr++) {
                err = pthread_join(tid_reader[i_thr], &tret);
index d2bd36e6e4cde06b2a833353dc3f29b090a5014e..56ac28d419d2b38345c030e4b8535e981f347b69 100644 (file)
@@ -35,8 +35,6 @@ struct test_array {
        int a;
 };
 
-static volatile int test_go, test_stop;
-
 static unsigned long wdelay;
 
 static struct test_array *test_rcu_pointer;
@@ -98,19 +96,6 @@ static void set_affinity(void)
 #endif /* HAVE_SCHED_SETAFFINITY */
 }
 
-/*
- * returns 0 if test should end.
- */
-static int test_duration_write(void)
-{
-       return !test_stop;
-}
-
-static int test_duration_read(void)
-{
-       return !test_stop;
-}
-
 static DEFINE_URCU_TLS(unsigned long long, nr_writes);
 static DEFINE_URCU_TLS(unsigned long long, nr_reads);
 
@@ -135,10 +120,7 @@ void *thr_reader(void *_count)
 
        rcu_register_thread();
 
-       while (!test_go)
-       {
-       }
-       cmm_smp_mb();
+       wait_until_go();
 
        for (;;) {
                rcu_read_lock();
@@ -189,10 +171,7 @@ void *thr_writer(void *data)
                exit(-1);
        }
 
-       while (!test_go)
-       {
-       }
-       cmm_smp_mb();
+       wait_until_go();
 
        for (;;) {
                new = malloc(sizeof(*new));
@@ -345,13 +324,7 @@ int main(int argc, char **argv)
                        exit(1);
        }
 
-       cmm_smp_mb();
-
-       test_go = 1;
-
-       sleep(duration);
-
-       test_stop = 1;
+       test_for(duration);
 
        for (i_thr = 0; i_thr < nr_readers; i_thr++) {
                err = pthread_join(tid_reader[i_thr], &tret);
index e2f64985297c9c77beca631f9484a90214adfafc..d52a51df87278328e4c7995ded69f669bc7ceb49 100644 (file)
@@ -19,6 +19,7 @@
 #include <urcu/arch.h>
 #include <urcu/assert.h>
 #include <urcu/tls-compat.h>
+#include <urcu/uatomic.h>
 #include "thread-id.h"
 #include "../common/debug-yield.h"
 
@@ -34,8 +35,6 @@ struct test_array {
        int a;
 };
 
-static volatile int test_go, test_stop;
-
 static unsigned long wdelay;
 
 static struct test_array *test_rcu_pointer;
@@ -106,19 +105,6 @@ static void set_affinity(void)
 #endif /* HAVE_SCHED_SETAFFINITY */
 }
 
-/*
- * returns 0 if test should end.
- */
-static int test_duration_write(void)
-{
-       return !test_stop;
-}
-
-static int test_duration_read(void)
-{
-       return !test_stop;
-}
-
 static DEFINE_URCU_TLS(unsigned long long, nr_writes);
 static DEFINE_URCU_TLS(unsigned long long, nr_reads);
 
@@ -143,10 +129,7 @@ void *thr_reader(void *_count)
 
        rcu_register_thread();
 
-       while (!test_go)
-       {
-       }
-       cmm_smp_mb();
+       wait_until_go();
 
        for (;;) {
                rcu_read_lock();
@@ -217,10 +200,7 @@ void *thr_writer(void *data)
 
        set_affinity();
 
-       while (!test_go)
-       {
-       }
-       cmm_smp_mb();
+       wait_until_go();
 
        for (;;) {
 #ifndef TEST_LOCAL_GC
@@ -385,13 +365,7 @@ int main(int argc, char **argv)
                        exit(1);
        }
 
-       cmm_smp_mb();
-
-       test_go = 1;
-
-       sleep(duration);
-
-       test_stop = 1;
+       test_for(duration);
 
        for (i_thr = 0; i_thr < nr_readers; i_thr++) {
                err = pthread_join(tid_reader[i_thr], &tret);
index c0b574d1a8692ab65c458e1e5334d71262d6a14a..606851baf37ee1b5a84e63b9e8c3cbe3e2a74e48 100644 (file)
@@ -82,8 +82,6 @@ DEFINE_URCU_TLS(unsigned long, lookup_ok);
 
 struct cds_lfht *test_ht;
 
-volatile int test_go, test_stop;
-
 unsigned long wdelay;
 
 unsigned long duration;
@@ -635,14 +633,14 @@ int main(int argc, char **argv)
 
        cmm_smp_mb();
 
-       test_go = 1;
+       begin_test();
 
        remain = duration;
        do {
                remain = sleep(remain);
        } while (remain > 0);
 
-       test_stop = 1;
+       end_test();
 
 end_pthread_join:
        for (i_thr = 0; i_thr < nr_readers_created; i_thr++) {
index 530a68bcd1b04c304c9c0ec06e712446d41278f9..0ecb781a129b2804b74a5ae8253ae2d7bd030b97 100644 (file)
@@ -111,8 +111,6 @@ cds_lfht_iter_get_test_node(struct cds_lfht_iter *iter)
        return to_test_node(cds_lfht_iter_get_node(iter));
 }
 
-extern volatile int test_go, test_stop;
-
 extern unsigned long wdelay;
 
 extern unsigned long duration;
@@ -160,19 +158,6 @@ extern pthread_mutex_t affinity_mutex;
 
 void set_affinity(void);
 
-/*
- * returns 0 if test should end.
- */
-static inline int test_duration_write(void)
-{
-       return !test_stop;
-}
-
-static inline int test_duration_read(void)
-{
-       return !test_stop;
-}
-
 extern DECLARE_URCU_TLS(unsigned long long, nr_writes);
 extern DECLARE_URCU_TLS(unsigned long long, nr_reads);
 
index 0c4ab20b53d5c3dc35fa2a50316c0f8bb72da5ad..b76603e6742db7f702ed38d46cd6c73fac4bfff3 100644 (file)
@@ -59,10 +59,7 @@ void *test_hash_rw_thr_reader(void *_count)
 
        rcu_register_thread();
 
-       while (!test_go)
-       {
-       }
-       cmm_smp_mb();
+       wait_until_go();
 
        for (;;) {
                rcu_read_lock();
@@ -119,10 +116,7 @@ void *test_hash_rw_thr_writer(void *_count)
 
        rcu_register_thread();
 
-       while (!test_go)
-       {
-       }
-       cmm_smp_mb();
+       wait_until_go();
 
        for (;;) {
                struct cds_lfht_node *ret_node = NULL;
index b8381b5c9e37478c8b9f8052669f09bbd3bc805a..487baa878e698cc01bad314cd34d5b77cb615fe0 100644 (file)
@@ -57,10 +57,7 @@ void *test_hash_unique_thr_reader(void *_count)
 
        rcu_register_thread();
 
-       while (!test_go)
-       {
-       }
-       cmm_smp_mb();
+       wait_until_go();
 
        for (;;) {
                struct lfht_test_node *node;
@@ -122,10 +119,7 @@ void *test_hash_unique_thr_writer(void *_count)
 
        rcu_register_thread();
 
-       while (!test_go)
-       {
-       }
-       cmm_smp_mb();
+       wait_until_go();
 
        for (;;) {
                /*
index 2217760b0f9ae18f56ac887fb6a06f417b710ca4..66cf78ca36aa0e4668e663461cd2c84a7c12f8c6 100644 (file)
@@ -33,8 +33,6 @@
 #include <urcu.h>
 #include <urcu/cds.h>
 
-static volatile int test_go, test_stop;
-
 static unsigned long rduration;
 
 static unsigned long duration;
@@ -96,12 +94,12 @@ static void set_affinity(void)
  */
 static int test_duration_dequeue(void)
 {
-       return !test_stop;
+       return test_duration_read();
 }
 
 static int test_duration_enqueue(void)
 {
-       return !test_stop;
+       return test_duration_write();
 }
 
 static DEFINE_URCU_TLS(unsigned long long, nr_dequeues);
@@ -132,10 +130,7 @@ void *thr_enqueuer(void *_count)
 
        rcu_register_thread();
 
-       while (!test_go)
-       {
-       }
-       cmm_smp_mb();
+       wait_until_go();
 
        for (;;) {
                struct test *node = malloc(sizeof(*node));
@@ -188,10 +183,7 @@ void *thr_dequeuer(void *_count)
 
        rcu_register_thread();
 
-       while (!test_go)
-       {
-       }
-       cmm_smp_mb();
+       wait_until_go();
 
        for (;;) {
                struct cds_lfq_node_rcu *qnode;
@@ -361,7 +353,7 @@ int main(int argc, char **argv)
 
        cmm_smp_mb();
 
-       test_go = 1;
+       begin_test();
 
        for (i_thr = 0; i_thr < duration; i_thr++) {
                sleep(1);
@@ -371,7 +363,7 @@ int main(int argc, char **argv)
                }
        }
 
-       test_stop = 1;
+       end_test();
 
        for (i_thr = 0; i_thr < nr_enqueuers; i_thr++) {
                err = pthread_join(tid_enqueuer[i_thr], &tret);
index c070021e395e2211892e573f44a29352da7c2eee..933f0b37bfdb01c6ce8d8d618b4945569e983d61 100644 (file)
@@ -45,8 +45,6 @@ enum test_sync {
 
 static enum test_sync test_sync;
 
-static volatile int test_go, test_stop;
-
 static unsigned long rduration;
 
 static unsigned long duration;
@@ -110,12 +108,12 @@ static void set_affinity(void)
  */
 static int test_duration_dequeue(void)
 {
-       return !test_stop;
+       return test_duration_read();
 }
 
 static int test_duration_enqueue(void)
 {
-       return !test_stop;
+       return test_duration_write();
 }
 
 static DEFINE_URCU_TLS(unsigned long long, nr_dequeues);
@@ -145,10 +143,7 @@ static void *thr_enqueuer(void *_count)
 
        rcu_register_thread();
 
-       while (!test_go)
-       {
-       }
-       cmm_smp_mb();
+       wait_until_go();
 
        for (;;) {
                struct test *node = malloc(sizeof(*node));
@@ -247,10 +242,7 @@ static void *thr_dequeuer(void *_count)
 
        rcu_register_thread();
 
-       while (!test_go)
-       {
-       }
-       cmm_smp_mb();
+       wait_until_go();
 
        urcu_posix_assert(test_pop || test_pop_all);
 
@@ -445,7 +437,7 @@ int main(int argc, char **argv)
 
        cmm_smp_mb();
 
-       test_go = 1;
+       begin_test();
 
        for (i_thr = 0; i_thr < duration; i_thr++) {
                sleep(1);
@@ -455,7 +447,7 @@ int main(int argc, char **argv)
                }
        }
 
-       test_stop = 1;
+       end_test();
 
        for (i_thr = 0; i_thr < nr_enqueuers; i_thr++) {
                err = pthread_join(tid_enqueuer[i_thr], &tret);
index 7aabc1d3370a1a6acd942b57d757b990b89bd1d9..cb9236d87d05a0209b3392a1aa47a34345c612f9 100644 (file)
@@ -37,8 +37,6 @@
 
 #include <urcu/cds.h>
 
-static volatile int test_go, test_stop;
-
 static unsigned long rduration;
 
 static unsigned long duration;
@@ -100,12 +98,12 @@ static void set_affinity(void)
  */
 static int test_duration_dequeue(void)
 {
-       return !test_stop;
+       return test_duration_read();
 }
 
 static int test_duration_enqueue(void)
 {
-       return !test_stop;
+       return test_duration_write();
 }
 
 static DEFINE_URCU_TLS(unsigned long long, nr_dequeues);
@@ -136,10 +134,7 @@ void *thr_enqueuer(void *_count)
 
        rcu_register_thread();
 
-       while (!test_go)
-       {
-       }
-       cmm_smp_mb();
+       wait_until_go();
 
        for (;;) {
                struct test *node = malloc(sizeof(*node));
@@ -191,10 +186,7 @@ void *thr_dequeuer(void *_count)
 
        rcu_register_thread();
 
-       while (!test_go)
-       {
-       }
-       cmm_smp_mb();
+       wait_until_go();
 
        for (;;) {
                struct cds_lfs_node_rcu *snode;
@@ -363,7 +355,7 @@ int main(int argc, char **argv)
 
        cmm_smp_mb();
 
-       test_go = 1;
+       begin_test();
 
        for (i_thr = 0; i_thr < duration; i_thr++) {
                sleep(1);
@@ -373,7 +365,7 @@ int main(int argc, char **argv)
                }
        }
 
-       test_stop = 1;
+       end_test();
 
        for (i_thr = 0; i_thr < nr_enqueuers; i_thr++) {
                err = pthread_join(tid_enqueuer[i_thr], &tret);
index cb09b387821871507365f15cd263a6b7e3be5164..a33dbd342df734baae3fc92678619a72f7116bb1 100644 (file)
@@ -30,8 +30,6 @@
 #endif
 #include "urcu-qsbr.h"
 
-static volatile int test_go, test_stop;
-
 static unsigned long wdelay;
 
 static int *test_rcu_pointer;
@@ -92,19 +90,6 @@ static void set_affinity(void)
 #endif /* HAVE_SCHED_SETAFFINITY */
 }
 
-/*
- * returns 0 if test should end.
- */
-static int test_duration_write(void)
-{
-       return !test_stop;
-}
-
-static int test_duration_read(void)
-{
-       return !test_stop;
-}
-
 static DEFINE_URCU_TLS(unsigned long long, nr_writes);
 static DEFINE_URCU_TLS(unsigned long long, nr_reads);
 
@@ -131,10 +116,7 @@ void *thr_reader(void *_count)
        urcu_posix_assert(!rcu_read_ongoing());
        rcu_thread_online();
 
-       while (!test_go)
-       {
-       }
-       cmm_smp_mb();
+       wait_until_go();
 
        for (;;) {
                rcu_read_lock();
@@ -178,10 +160,7 @@ void *thr_writer(void *_count)
 
        set_affinity();
 
-       while (!test_go)
-       {
-       }
-       cmm_smp_mb();
+       wait_until_go();
 
        for (;;) {
                new = malloc(sizeof(int));
@@ -329,13 +308,7 @@ int main(int argc, char **argv)
                        exit(1);
        }
 
-       cmm_smp_mb();
-
-       test_go = 1;
-
-       sleep(duration);
-
-       test_stop = 1;
+       test_for(duration);
 
        for (i_thr = 0; i_thr < nr_readers; i_thr++) {
                err = pthread_join(tid_reader[i_thr], &tret);
index 47d23bc470c682c00873f07dc40925149aebf8d5..00f6757c9d294348cb969b015f4b658831301e7d 100644 (file)
@@ -19,6 +19,7 @@
 #include <urcu/arch.h>
 #include <urcu/assert.h>
 #include <urcu/tls-compat.h>
+#include <urcu/uatomic.h>
 #include "thread-id.h"
 #include "../common/debug-yield.h"
 
@@ -32,8 +33,6 @@ struct test_array {
        int a;
 };
 
-static volatile int test_go, test_stop;
-
 static unsigned long wdelay;
 
 static struct test_array *test_rcu_pointer;
@@ -104,19 +103,6 @@ static void set_affinity(void)
 #endif /* HAVE_SCHED_SETAFFINITY */
 }
 
-/*
- * returns 0 if test should end.
- */
-static int test_duration_write(void)
-{
-       return !test_stop;
-}
-
-static int test_duration_read(void)
-{
-       return !test_stop;
-}
-
 static DEFINE_URCU_TLS(unsigned long long, nr_writes);
 static DEFINE_URCU_TLS(unsigned long long, nr_reads);
 
@@ -140,10 +126,7 @@ void *thr_reader(void *_count)
 
        rcu_register_thread();
 
-       while (!test_go)
-       {
-       }
-       cmm_smp_mb();
+       wait_until_go();
 
        for (;;) {
                _rcu_read_lock();
@@ -217,10 +200,7 @@ void *thr_writer(void *data)
 
        set_affinity();
 
-       while (!test_go)
-       {
-       }
-       cmm_smp_mb();
+       wait_until_go();
 
        for (;;) {
 #ifndef TEST_LOCAL_GC
@@ -385,13 +365,7 @@ int main(int argc, char **argv)
                        exit(1);
        }
 
-       cmm_smp_mb();
-
-       test_go = 1;
-
-       sleep(duration);
-
-       test_stop = 1;
+       test_for(duration);
 
        for (i_thr = 0; i_thr < nr_readers; i_thr++) {
                err = pthread_join(tid_reader[i_thr], &tret);
index 7f18af0615c79a0f5814e9f58bf99d463a52991b..71bca100cd45670e15ff452eabfab389b0023d1a 100644 (file)
@@ -42,7 +42,7 @@ static enum test_sync test_sync;
 
 static int test_force_sync;
 
-static volatile int test_go, test_stop_enqueue, test_stop_dequeue;
+static volatile int test_stop_enqueue, test_stop_dequeue;
 
 static unsigned long rduration;
 
@@ -108,12 +108,12 @@ static void set_affinity(void)
  */
 static int test_duration_dequeue(void)
 {
-       return !test_stop_dequeue;
+       return !uatomic_load(&test_stop_dequeue, CMM_RELAXED);
 }
 
 static int test_duration_enqueue(void)
 {
-       return !test_stop_enqueue;
+       return !uatomic_load(&test_stop_enqueue, CMM_RELAXED);
 }
 
 static DEFINE_URCU_TLS(unsigned long long, nr_dequeues);
@@ -141,10 +141,7 @@ static void *thr_enqueuer(void *_count)
 
        set_affinity();
 
-       while (!test_go)
-       {
-       }
-       cmm_smp_mb();
+       wait_until_go();
 
        for (;;) {
                struct cds_wfcq_node *node = malloc(sizeof(*node));
@@ -252,10 +249,7 @@ static void *thr_dequeuer(void *_count)
 
        set_affinity();
 
-       while (!test_go)
-       {
-       }
-       cmm_smp_mb();
+       wait_until_go();
 
        for (;;) {
                if (test_dequeue && test_splice) {
@@ -468,7 +462,7 @@ int main(int argc, char **argv)
 
        cmm_smp_mb();
 
-       test_go = 1;
+       begin_test();
 
        for (i_thr = 0; i_thr < duration; i_thr++) {
                sleep(1);
@@ -478,7 +472,7 @@ int main(int argc, char **argv)
                }
        }
 
-       test_stop_enqueue = 1;
+       uatomic_store(&test_stop_enqueue, 1, CMM_RELEASE);
 
        if (test_wait_empty) {
                while (nr_enqueuers != uatomic_read(&test_enqueue_stopped)) {
@@ -489,7 +483,7 @@ int main(int argc, char **argv)
                }
        }
 
-       test_stop_dequeue = 1;
+       uatomic_store(&test_stop_dequeue, 1, CMM_RELAXED);
 
        for (i_thr = 0; i_thr < nr_enqueuers; i_thr++) {
                err = pthread_join(tid_enqueuer[i_thr], &tret);
index c11f63980068c806abea49f322ec9902d82aba8d..b17df5ac37787b432c3456a82ecba6b21303e03f 100644 (file)
@@ -37,8 +37,6 @@
 #include <urcu.h>
 #include <urcu/wfqueue.h>
 
-static volatile int test_go, test_stop;
-
 static unsigned long rduration;
 
 static unsigned long duration;
@@ -100,12 +98,12 @@ static void set_affinity(void)
  */
 static int test_duration_dequeue(void)
 {
-       return !test_stop;
+       return test_duration_read();
 }
 
 static int test_duration_enqueue(void)
 {
-       return !test_stop;
+       return test_duration_write();
 }
 
 static DEFINE_URCU_TLS(unsigned long long, nr_dequeues);
@@ -129,10 +127,7 @@ void *thr_enqueuer(void *_count)
 
        set_affinity();
 
-       while (!test_go)
-       {
-       }
-       cmm_smp_mb();
+       wait_until_go();
 
        for (;;) {
                struct cds_wfq_node *node = malloc(sizeof(*node));
@@ -171,10 +166,7 @@ void *thr_dequeuer(void *_count)
 
        set_affinity();
 
-       while (!test_go)
-       {
-       }
-       cmm_smp_mb();
+       wait_until_go();
 
        for (;;) {
                struct cds_wfq_node *node = cds_wfq_dequeue_blocking(&q);
@@ -329,7 +321,7 @@ int main(int argc, char **argv)
 
        cmm_smp_mb();
 
-       test_go = 1;
+       begin_test();
 
        for (i_thr = 0; i_thr < duration; i_thr++) {
                sleep(1);
@@ -339,7 +331,7 @@ int main(int argc, char **argv)
                }
        }
 
-       test_stop = 1;
+       end_test();
 
        for (i_thr = 0; i_thr < nr_enqueuers; i_thr++) {
                err = pthread_join(tid_enqueuer[i_thr], &tret);
index 9b9c2f8730ae3f13c41351ea955c6c686a2b2b9c..39704f4acb5cce5eee13112fa127d78bea31e6d7 100644 (file)
@@ -45,7 +45,7 @@ static enum test_sync test_sync;
 
 static int test_force_sync;
 
-static volatile int test_go, test_stop_enqueue, test_stop_dequeue;
+static volatile int test_stop_enqueue, test_stop_dequeue;
 
 static unsigned long rduration;
 
@@ -111,12 +111,12 @@ static void set_affinity(void)
  */
 static int test_duration_dequeue(void)
 {
-       return !test_stop_dequeue;
+       return !uatomic_load(&test_stop_dequeue, CMM_RELAXED);
 }
 
 static int test_duration_enqueue(void)
 {
-       return !test_stop_enqueue;
+       return !uatomic_load(&test_stop_enqueue, CMM_RELAXED);
 }
 
 static DEFINE_URCU_TLS(unsigned long long, nr_dequeues);
@@ -143,10 +143,7 @@ static void *thr_enqueuer(void *_count)
 
        set_affinity();
 
-       while (!test_go)
-       {
-       }
-       cmm_smp_mb();
+       wait_until_go();
 
        for (;;) {
                struct cds_wfs_node *node = malloc(sizeof(*node));
@@ -236,10 +233,7 @@ static void *thr_dequeuer(void *_count)
 
        set_affinity();
 
-       while (!test_go)
-       {
-       }
-       cmm_smp_mb();
+       wait_until_go();
 
        urcu_posix_assert(test_pop || test_pop_all);
 
@@ -455,7 +449,7 @@ int main(int argc, char **argv)
 
        cmm_smp_mb();
 
-       test_go = 1;
+       begin_test();
 
        for (i_thr = 0; i_thr < duration; i_thr++) {
                sleep(1);
@@ -465,7 +459,7 @@ int main(int argc, char **argv)
                }
        }
 
-       test_stop_enqueue = 1;
+       uatomic_store(&test_stop_enqueue, 1, CMM_RELEASE);
 
        if (test_wait_empty) {
                while (nr_enqueuers != uatomic_read(&test_enqueue_stopped)) {
@@ -476,7 +470,7 @@ int main(int argc, char **argv)
                }
        }
 
-       test_stop_dequeue = 1;
+       uatomic_store(&test_stop_dequeue, 1, CMM_RELAXED);
 
        for (i_thr = 0; i_thr < nr_enqueuers; i_thr++) {
                err = pthread_join(tid_enqueuer[i_thr], &tret);
This page took 0.049927 seconds and 4 git commands to generate.