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>
This commit is contained in:
David Lamparter 2024-06-20 12:02:25 +02:00
parent b9541fe77f
commit e14c94f2b7

View file

@ -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 {
@ -98,8 +98,8 @@ static void trfunc_##name(unsigned int offset) \
size_t i = 0, n = 0;
#define endtestrun \
thr[offset].counter = i; \
thr[offset].nullops = n; \
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)
@ -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);