From c2b705c5cea63882e3f6755b605aa7440a722e4f Mon Sep 17 00:00:00 2001 From: faluco Date: Wed, 15 Sep 2021 17:10:54 +0200 Subject: [PATCH] Fix several data races in proc_phr, class needs to be fully protected since most member variables are accessed by different threads. --- srsue/hdr/stack/mac/proc_phr.h | 2 ++ srsue/src/stack/mac/proc_phr.cc | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/srsue/hdr/stack/mac/proc_phr.h b/srsue/hdr/stack/mac/proc_phr.h index 792b40fe2..3cd12f6dc 100644 --- a/srsue/hdr/stack/mac/proc_phr.h +++ b/srsue/hdr/stack/mac/proc_phr.h @@ -52,6 +52,8 @@ private: srsran::timer_handler::unique_timer timer_periodic; srsran::timer_handler::unique_timer timer_prohibit; + + std::mutex mutex; }; } // namespace srsue diff --git a/srsue/src/stack/mac/proc_phr.cc b/srsue/src/stack/mac/proc_phr.cc index e604c6354..07415918a 100644 --- a/srsue/src/stack/mac/proc_phr.cc +++ b/srsue/src/stack/mac/proc_phr.cc @@ -41,6 +41,7 @@ void phr_proc::init(phy_interface_mac_lte* phy_h_, srsran::ext_task_sched_handle void phr_proc::reset() { + std::lock_guard lock(mutex); timer_periodic.stop(); timer_prohibit.stop(); phr_is_triggered = false; @@ -48,6 +49,8 @@ void phr_proc::reset() void phr_proc::set_config(srsran::phr_cfg_t& cfg) { + std::lock_guard lock(mutex); + phr_cfg = cfg; // First stop timers. If enabled==false or value is Inf, won't be re-started @@ -90,6 +93,7 @@ bool phr_proc::pathloss_changed() void phr_proc::start_periodic_timer() { + std::lock_guard lock(mutex); if (phr_cfg.enabled && phr_cfg.periodic_timer > 0) { timer_periodic.run(); } @@ -98,6 +102,7 @@ void phr_proc::start_periodic_timer() /* Trigger PHR when timers exires */ void phr_proc::timer_expired(uint32_t timer_id) { + std::lock_guard lock(mutex); if (!phr_cfg.enabled) { Warning("PHR: %s timer triggered but PHR has been disabled", timer_id == timer_periodic.id() ? "Periodic" : "Prohibit"); @@ -119,6 +124,8 @@ void phr_proc::timer_expired(uint32_t timer_id) void phr_proc::step() { + std::lock_guard lock(mutex); + if (phr_cfg.enabled && initiated) { if (pathloss_changed() && timer_prohibit.is_expired()) { Info("PHR: Triggered by pathloss difference. cur_pathloss_db=%d", last_pathloss_db); @@ -129,6 +136,7 @@ void phr_proc::step() bool phr_proc::generate_phr_on_ul_grant(float* phr) { + std::lock_guard lock(mutex); if (phr_is_triggered) { if (phr) { *phr = phy_h->get_phr(); @@ -149,6 +157,7 @@ bool phr_proc::generate_phr_on_ul_grant(float* phr) bool phr_proc::is_extended() { + std::lock_guard lock(mutex); return phr_cfg.extended; } } // namespace srsue