summaryrefslogtreecommitdiff
path: root/tests/lib
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@opensourcerouting.org>2024-06-20 12:02:25 +0200
committerDavid Lamparter <equinox@opensourcerouting.org>2024-06-20 15:44:46 +0200
commite14c94f2b77692126210f4b7b51cf097d7f847e0 (patch)
tree7c51fc0697b0493c312e17c7c3823323817d5fe4 /tests/lib
parentb9541fe77fcb706c3f265d704e15f810b0a98c14 (diff)
tests: fix TSAN warnings in atomlist test
The atomlist test consists of a sequence of (MT) sub-tests, from which counters are collected and verified. TSAN doesn't know that these counters are synchronized by way of the sub-test starting and finishing, so it complains. Just use atomics to get rid of the warning. (This is solely an issue with the test, not the atomlist code. There are no warnings from that.) Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'tests/lib')
-rw-r--r--tests/lib/test_atomlist.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/tests/lib/test_atomlist.c b/tests/lib/test_atomlist.c
index b50216cf92..afcfa98791 100644
--- a/tests/lib/test_atomlist.c
+++ b/tests/lib/test_atomlist.c
@@ -62,7 +62,7 @@ static struct asort_head shead;
static struct testthread {
pthread_t pt;
struct seqlock sqlo;
- size_t counter, nullops;
+ _Atomic size_t counter, nullops;
} thr[NTHREADS];
struct testrun {
@@ -97,10 +97,10 @@ static void trfunc_##name(unsigned int offset) \
{ \
size_t i = 0, n = 0;
-#define endtestrun \
- thr[offset].counter = i; \
- thr[offset].nullops = n; \
-}
+#define endtestrun \
+ atomic_store_explicit(&thr[offset].counter, i, memory_order_seq_cst); \
+ atomic_store_explicit(&thr[offset].nullops, n, memory_order_seq_cst); \
+ }
deftestrun(add, "add vs. add", 0, false)
for (; i < NITEM / NTHREADS; i++)
@@ -288,10 +288,10 @@ static void run_tr(struct testrun *tr)
sv = seqlock_bump(&sqlo) - SEQLOCK_INCR;
for (size_t i = 0; i < NTHREADS; i++) {
seqlock_wait(&thr[i].sqlo, seqlock_cur(&sqlo));
- s += thr[i].counter;
- n += thr[i].nullops;
- thr[i].counter = 0;
- thr[i].nullops = 0;
+ s += atomic_load_explicit(&thr[i].counter, memory_order_seq_cst);
+ n += atomic_load_explicit(&thr[i].nullops, memory_order_seq_cst);
+ atomic_store_explicit(&thr[i].counter, 0, memory_order_seq_cst);
+ atomic_store_explicit(&thr[i].nullops, 0, memory_order_seq_cst);
}
delta = monotime_since(&tv, NULL);