From 4a9e3728c93f30b679c854665ffd5772e1db257a Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Tue, 17 Dec 2019 16:06:35 +0100 Subject: [PATCH] add condtional variable for PHY initialization and configuration adding a cond variable and mutex to protect init and (re-)config of PHY currently this is only used during init. If the stack couldn't be initialized but the PHY init thread was already started, we need to properly wait until this is done --- srsue/hdr/phy/phy.h | 4 +++- srsue/src/phy/phy.cc | 20 ++++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/srsue/hdr/phy/phy.h b/srsue/hdr/phy/phy.h index c6f6e31fa..03b64a6bc 100644 --- a/srsue/hdr/phy/phy.h +++ b/srsue/hdr/phy/phy.h @@ -134,7 +134,9 @@ public: private: void run_thread() final; - bool initiated = false; + std::mutex config_mutex; + std::condition_variable config_cond; + bool is_configured = false; uint32_t nof_workers = 0; const static int SF_RECV_THREAD_PRIO = 1; diff --git a/srsue/src/phy/phy.cc b/srsue/src/phy/phy.cc index 82ba3970a..c305ef1e0 100644 --- a/srsue/src/phy/phy.cc +++ b/srsue/src/phy/phy.cc @@ -122,6 +122,7 @@ int phy::init(const phy_args_t& args_, stack_interface_phy_lte* stack_, srslte:: int phy::init(const phy_args_t& args_) { + std::unique_lock lock(config_mutex); mlockall(MCL_CURRENT | MCL_FUTURE); args = args_; @@ -172,7 +173,7 @@ int phy::init(const phy_args_t& args_) this->log_phy_lib_h = nullptr; } - initiated = false; + is_configured = false; start(); return true; } @@ -180,6 +181,7 @@ int phy::init(const phy_args_t& args_) // Initializes PHY in a thread void phy::run_thread() { + std::unique_lock lock(config_mutex); prach_buffer.init(SRSLTE_MAX_PRB, log_h); common.init(&args, (srslte::log*)log_vec[0].get(), radio, stack); @@ -213,22 +215,28 @@ void phy::run_thread() // Disable UL signal pregeneration until the attachment enable_pregen_signals(false); - initiated = true; + is_configured = true; + config_cond.notify_all(); } void phy::wait_initialize() { - wait_thread_finish(); + // wait until PHY is configured + std::unique_lock lock(config_mutex); + while (!is_configured) { + config_cond.wait(lock); + } } bool phy::is_initiated() { - return initiated; + return is_configured; } void phy::stop() { - if (initiated) { + std::unique_lock lock(config_mutex); + if (is_configured) { sfsync.stop(); for (uint32_t i = 0; i < args.nof_radios - 1; i++) { scell_sync.at(i)->stop(); @@ -237,7 +245,7 @@ void phy::stop() workers_pool.stop(); prach_buffer.stop(); - initiated = false; + is_configured = false; } }