From f823340a95cdbb3462d2015f4ed26a6058ffab60 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Thu, 27 May 2021 21:47:39 +0200 Subject: [PATCH] rf_imp: fix race when stopping gain thread detected with TSAN using benchmark_radio test --- lib/src/phy/rf/rf_imp.c | 2 ++ lib/src/radio/test/benchmark_radio.cc | 1 + 2 files changed, 3 insertions(+) diff --git a/lib/src/phy/rf/rf_imp.c b/lib/src/phy/rf/rf_imp.c index 8ed99f0c0..eb0cac1ad 100644 --- a/lib/src/phy/rf/rf_imp.c +++ b/lib/src/phy/rf/rf_imp.c @@ -175,7 +175,9 @@ int srsran_rf_close(srsran_rf_t* rf) { // Stop gain thread if (rf->thread_gain_run) { + pthread_mutex_lock(&rf->mutex); rf->thread_gain_run = false; + pthread_mutex_unlock(&rf->mutex); pthread_cond_signal(&rf->cond); pthread_join(rf->thread_gain, NULL); } diff --git a/lib/src/radio/test/benchmark_radio.cc b/lib/src/radio/test/benchmark_radio.cc index 26c9f3f23..ab88adcfd 100644 --- a/lib/src/radio/test/benchmark_radio.cc +++ b/lib/src/radio/test/benchmark_radio.cc @@ -25,6 +25,7 @@ extern "C" { //#undef I // Fix complex.h #define I nastiness when using C++ #endif +#include "srsran/common/tsan_options.h" #include "srsran/phy/utils/debug.h" #include "srsran/radio/radio.h"