ue,proc_sr_nr: add mutex to protect access from PHY and Stack

also detected by TSAN
This commit is contained in:
Andre Puschmann 2021-09-15 10:05:44 +02:00 committed by Xavier Arteaga
parent 2248e63219
commit ab6210b1fc
2 changed files with 17 additions and 4 deletions

View File

@ -13,10 +13,11 @@
#ifndef SRSUE_PROC_SR_NR_H
#define SRSUE_PROC_SR_NR_H
#include "srsue/hdr/stack/mac_nr/mac_nr_interfaces.h"
#include "srsran/interfaces/ue_mac_interfaces.h"
#include "srsran/interfaces/ue_nr_interfaces.h"
#include "srsran/srslog/srslog.h"
#include "srsue/hdr/stack/mac_nr/mac_nr_interfaces.h"
#include <mutex>
#include <stdint.h>
/// Scheduling Request procedure as defined in 5.4.4 of 38.321
@ -39,6 +40,7 @@ public:
bool sr_opportunity(uint32_t tti, uint32_t sr_id, bool meas_gap, bool ul_sch_tx);
private:
void reset_unsafe();
int sr_counter = 0;
bool is_pending_sr = false;
@ -49,7 +51,8 @@ private:
phy_interface_mac_nr* phy = nullptr;
srslog::basic_logger& logger;
bool initiated = false;
bool initiated = false;
std::mutex mutex;
};
} // namespace srsue

View File

@ -21,6 +21,7 @@ proc_sr_nr::proc_sr_nr(srslog::basic_logger& logger) : logger(logger) {}
int32_t proc_sr_nr::init(mac_interface_sr_nr* mac_, phy_interface_mac_nr* phy_, rrc_interface_mac* rrc_)
{
std::lock_guard<std::mutex> lock(mutex);
rrc = rrc_;
mac = mac_;
phy = phy_;
@ -32,6 +33,12 @@ int32_t proc_sr_nr::init(mac_interface_sr_nr* mac_, phy_interface_mac_nr* phy_,
}
void proc_sr_nr::reset()
{
std::lock_guard<std::mutex> lock(mutex);
reset_unsafe();
}
void proc_sr_nr::reset_unsafe()
{
is_pending_sr = false;
}
@ -70,6 +77,7 @@ int32_t proc_sr_nr::set_config(const srsran::sr_cfg_nr_t& cfg_)
void proc_sr_nr::step(uint32_t tti)
{
std::lock_guard<std::mutex> lock(mutex);
if (!initiated) {
return;
}
@ -84,7 +92,7 @@ void proc_sr_nr::step(uint32_t tti)
// 2> initiate a Random Access procedure (see clause 5.1) on the SpCell and cancel the pending SR.
logger.info("SR: PUCCH not configured. Starting RA procedure");
mac->start_ra();
reset();
reset_unsafe();
return;
}
@ -102,12 +110,13 @@ void proc_sr_nr::step(uint32_t tti)
// ... TODO
mac->start_ra();
reset();
reset_unsafe();
}
}
bool proc_sr_nr::sr_opportunity(uint32_t tti, uint32_t sr_id, bool meas_gap, bool ul_sch_tx)
{
std::lock_guard<std::mutex> lock(mutex);
// 2> when the MAC entity has an SR transmission occasion on the valid PUCCH resource for SR configured; and
if (!initiated || !cfg.enabled || !is_pending_sr) {
return false;
@ -147,6 +156,7 @@ bool proc_sr_nr::sr_opportunity(uint32_t tti, uint32_t sr_id, bool meas_gap, boo
void proc_sr_nr::start()
{
std::lock_guard<std::mutex> lock(mutex);
if (initiated) {
if (not is_pending_sr) {
logger.info("SR: Starting procedure");