From c0163d73894c15a5dc9320536ccff6bf2089d2ad Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Thu, 29 Jul 2021 18:12:03 +0200 Subject: [PATCH] nr,slot_worker: add mutex to protect class from concurrent access detected during debug while slot_worker was still initialized on the main process, the PHY workers were already running and accessing class members --- srsenb/hdr/phy/nr/slot_worker.h | 1 + srsenb/src/phy/nr/slot_worker.cc | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/srsenb/hdr/phy/nr/slot_worker.h b/srsenb/hdr/phy/nr/slot_worker.h index 776d8dadb..ab90890e5 100644 --- a/srsenb/hdr/phy/nr/slot_worker.h +++ b/srsenb/hdr/phy/nr/slot_worker.h @@ -86,6 +86,7 @@ private: srsran_gnb_ul_t gnb_ul = {}; std::vector tx_buffer; ///< Baseband transmit buffers std::vector rx_buffer; ///< Baseband receive buffers + std::mutex mutex; ///< Protect concurrent access from workers (and main process that inits the class) }; } // namespace nr diff --git a/srsenb/src/phy/nr/slot_worker.cc b/srsenb/src/phy/nr/slot_worker.cc index 814b9d33e..345a19927 100644 --- a/srsenb/src/phy/nr/slot_worker.cc +++ b/srsenb/src/phy/nr/slot_worker.cc @@ -27,6 +27,8 @@ slot_worker::slot_worker(srsran::phy_common_interface& common_, bool slot_worker::init(const args_t& args) { + std::lock_guard lock(mutex); + // Calculate subframe length sf_len = SRSRAN_SF_LEN_PRB_NR(args.nof_max_prb); @@ -104,6 +106,7 @@ slot_worker::~slot_worker() cf_t* slot_worker::get_buffer_rx(uint32_t antenna_idx) { + std::lock_guard lock(mutex); if (antenna_idx >= (uint32_t)rx_buffer.size()) { return nullptr; } @@ -113,6 +116,7 @@ cf_t* slot_worker::get_buffer_rx(uint32_t antenna_idx) cf_t* slot_worker::get_buffer_tx(uint32_t antenna_idx) { + std::lock_guard lock(mutex); if (antenna_idx >= (uint32_t)tx_buffer.size()) { return nullptr; }