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
master
Andre Puschmann 3 years ago committed by Xavier Arteaga
parent 2656014f43
commit c0163d7389

@ -86,6 +86,7 @@ private:
srsran_gnb_ul_t gnb_ul = {};
std::vector<cf_t*> tx_buffer; ///< Baseband transmit buffers
std::vector<cf_t*> rx_buffer; ///< Baseband receive buffers
std::mutex mutex; ///< Protect concurrent access from workers (and main process that inits the class)
};
} // namespace nr

@ -27,6 +27,8 @@ slot_worker::slot_worker(srsran::phy_common_interface& common_,
bool slot_worker::init(const args_t& args)
{
std::lock_guard<std::mutex> 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<std::mutex> 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<std::mutex> lock(mutex);
if (antenna_idx >= (uint32_t)tx_buffer.size()) {
return nullptr;
}

Loading…
Cancel
Save