Fix several data races in proc_phr, class needs to be fully protected since most member variables are accessed by different threads.

master
faluco 3 years ago committed by faluco
parent 6b07e886b7
commit c2b705c5ce

@ -52,6 +52,8 @@ private:
srsran::timer_handler::unique_timer timer_periodic; srsran::timer_handler::unique_timer timer_periodic;
srsran::timer_handler::unique_timer timer_prohibit; srsran::timer_handler::unique_timer timer_prohibit;
std::mutex mutex;
}; };
} // namespace srsue } // namespace srsue

@ -41,6 +41,7 @@ void phr_proc::init(phy_interface_mac_lte* phy_h_, srsran::ext_task_sched_handle
void phr_proc::reset() void phr_proc::reset()
{ {
std::lock_guard<std::mutex> lock(mutex);
timer_periodic.stop(); timer_periodic.stop();
timer_prohibit.stop(); timer_prohibit.stop();
phr_is_triggered = false; phr_is_triggered = false;
@ -48,6 +49,8 @@ void phr_proc::reset()
void phr_proc::set_config(srsran::phr_cfg_t& cfg) void phr_proc::set_config(srsran::phr_cfg_t& cfg)
{ {
std::lock_guard<std::mutex> lock(mutex);
phr_cfg = cfg; phr_cfg = cfg;
// First stop timers. If enabled==false or value is Inf, won't be re-started // 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() void phr_proc::start_periodic_timer()
{ {
std::lock_guard<std::mutex> lock(mutex);
if (phr_cfg.enabled && phr_cfg.periodic_timer > 0) { if (phr_cfg.enabled && phr_cfg.periodic_timer > 0) {
timer_periodic.run(); timer_periodic.run();
} }
@ -98,6 +102,7 @@ void phr_proc::start_periodic_timer()
/* Trigger PHR when timers exires */ /* Trigger PHR when timers exires */
void phr_proc::timer_expired(uint32_t timer_id) void phr_proc::timer_expired(uint32_t timer_id)
{ {
std::lock_guard<std::mutex> lock(mutex);
if (!phr_cfg.enabled) { if (!phr_cfg.enabled) {
Warning("PHR: %s timer triggered but PHR has been disabled", Warning("PHR: %s timer triggered but PHR has been disabled",
timer_id == timer_periodic.id() ? "Periodic" : "Prohibit"); timer_id == timer_periodic.id() ? "Periodic" : "Prohibit");
@ -119,6 +124,8 @@ void phr_proc::timer_expired(uint32_t timer_id)
void phr_proc::step() void phr_proc::step()
{ {
std::lock_guard<std::mutex> lock(mutex);
if (phr_cfg.enabled && initiated) { if (phr_cfg.enabled && initiated) {
if (pathloss_changed() && timer_prohibit.is_expired()) { if (pathloss_changed() && timer_prohibit.is_expired()) {
Info("PHR: Triggered by pathloss difference. cur_pathloss_db=%d", last_pathloss_db); 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) bool phr_proc::generate_phr_on_ul_grant(float* phr)
{ {
std::lock_guard<std::mutex> lock(mutex);
if (phr_is_triggered) { if (phr_is_triggered) {
if (phr) { if (phr) {
*phr = phy_h->get_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() bool phr_proc::is_extended()
{ {
std::lock_guard<std::mutex> lock(mutex);
return phr_cfg.extended; return phr_cfg.extended;
} }
} // namespace srsue } // namespace srsue

Loading…
Cancel
Save