From 7e8c52d80793e4f406177e82602cdf293a8a7fa8 Mon Sep 17 00:00:00 2001 From: Aaron Rossetto Date: Fri, 4 Mar 2022 12:00:47 -0600 Subject: tests: Atomicize counters in benchmark_rate The counters that keep track of overruns, underruns, number of samples transferred, etc., were not atomic. Thus, running benchmark_rate with multiple threads would result in inaccurate statistics being reported at the end of the run. This commit makes those counters atomic variables so that they are updated properly. --- host/examples/benchmark_rate.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'host/examples') diff --git a/host/examples/benchmark_rate.cpp b/host/examples/benchmark_rate.cpp index 5a3f5f181..41d3ff462 100644 --- a/host/examples/benchmark_rate.cpp +++ b/host/examples/benchmark_rate.cpp @@ -32,16 +32,16 @@ using start_time_type = std::chrono::time_point; /*********************************************************************** * Test result variables **********************************************************************/ -unsigned long long num_overruns = 0; -unsigned long long num_underruns = 0; -unsigned long long num_rx_samps = 0; -unsigned long long num_tx_samps = 0; -unsigned long long num_dropped_samps = 0; -unsigned long long num_seq_errors = 0; -unsigned long long num_seqrx_errors = 0; // "D"s -unsigned long long num_late_commands = 0; -unsigned long long num_timeouts_rx = 0; -unsigned long long num_timeouts_tx = 0; +std::atomic_ullong num_overruns{0}; +std::atomic_ullong num_underruns{0}; +std::atomic_ullong num_rx_samps{0}; +std::atomic_ullong num_tx_samps{0}; +std::atomic_ullong num_dropped_samps{0}; +std::atomic_ullong num_seq_errors{0}; +std::atomic_ullong num_seqrx_errors{0}; // "D"s +std::atomic_ullong num_late_commands{0}; +std::atomic_ullong num_timeouts_rx{0}; +std::atomic_ullong num_timeouts_tx{0}; inline auto time_delta(const start_time_type& ref_time) { -- cgit v1.2.3