diff --git a/srsue/hdr/stack/mac_nr/proc_sr_nr.h b/srsue/hdr/stack/mac_nr/proc_sr_nr.h index 1d0224350..ab57b0a5e 100644 --- a/srsue/hdr/stack/mac_nr/proc_sr_nr.h +++ b/srsue/hdr/stack/mac_nr/proc_sr_nr.h @@ -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 #include /// 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 diff --git a/srsue/src/stack/mac_nr/proc_sr_nr.cc b/srsue/src/stack/mac_nr/proc_sr_nr.cc index a35db5c69..e68b0483b 100644 --- a/srsue/src/stack/mac_nr/proc_sr_nr.cc +++ b/srsue/src/stack/mac_nr/proc_sr_nr.cc @@ -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 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 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 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 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 lock(mutex); if (initiated) { if (not is_pending_sr) { logger.info("SR: Starting procedure");