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
This commit is contained in:
Andre Puschmann 2019-12-17 16:06:35 +01:00
parent 705cd3c211
commit 4a9e3728c9
2 changed files with 17 additions and 7 deletions

View File

@ -134,7 +134,9 @@ public:
private: private:
void run_thread() final; 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; uint32_t nof_workers = 0;
const static int SF_RECV_THREAD_PRIO = 1; const static int SF_RECV_THREAD_PRIO = 1;

View File

@ -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_) int phy::init(const phy_args_t& args_)
{ {
std::unique_lock<std::mutex> lock(config_mutex);
mlockall(MCL_CURRENT | MCL_FUTURE); mlockall(MCL_CURRENT | MCL_FUTURE);
args = args_; args = args_;
@ -172,7 +173,7 @@ int phy::init(const phy_args_t& args_)
this->log_phy_lib_h = nullptr; this->log_phy_lib_h = nullptr;
} }
initiated = false; is_configured = false;
start(); start();
return true; return true;
} }
@ -180,6 +181,7 @@ int phy::init(const phy_args_t& args_)
// Initializes PHY in a thread // Initializes PHY in a thread
void phy::run_thread() void phy::run_thread()
{ {
std::unique_lock<std::mutex> lock(config_mutex);
prach_buffer.init(SRSLTE_MAX_PRB, log_h); prach_buffer.init(SRSLTE_MAX_PRB, log_h);
common.init(&args, (srslte::log*)log_vec[0].get(), radio, stack); 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 // Disable UL signal pregeneration until the attachment
enable_pregen_signals(false); enable_pregen_signals(false);
initiated = true; is_configured = true;
config_cond.notify_all();
} }
void phy::wait_initialize() void phy::wait_initialize()
{ {
wait_thread_finish(); // wait until PHY is configured
std::unique_lock<std::mutex> lock(config_mutex);
while (!is_configured) {
config_cond.wait(lock);
}
} }
bool phy::is_initiated() bool phy::is_initiated()
{ {
return initiated; return is_configured;
} }
void phy::stop() void phy::stop()
{ {
if (initiated) { std::unique_lock<std::mutex> lock(config_mutex);
if (is_configured) {
sfsync.stop(); sfsync.stop();
for (uint32_t i = 0; i < args.nof_radios - 1; i++) { for (uint32_t i = 0; i < args.nof_radios - 1; i++) {
scell_sync.at(i)->stop(); scell_sync.at(i)->stop();
@ -237,7 +245,7 @@ void phy::stop()
workers_pool.stop(); workers_pool.stop();
prach_buffer.stop(); prach_buffer.stop();
initiated = false; is_configured = false;
} }
} }