From a5c61418d5f01e2c6cdf441e9ee2ef127692853e Mon Sep 17 00:00:00 2001 From: Robert Falkenberg Date: Mon, 21 Mar 2022 10:39:39 +0100 Subject: [PATCH] lib,rf_imp: load rf plugins when loading this library This fixes race of concurrently loading the same plugins when srsran_rf_open_devname is called by multiple threads Plugins are now loaded when srsran_rf is loaded (for shared lib) or right before main() (for static lib) --- lib/src/phy/rf/rf_imp.c | 13 ++++++++----- lib/src/phy/rf/rf_zmq_test.c | 1 - 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/src/phy/rf/rf_imp.c b/lib/src/phy/rf/rf_imp.c index 30ff775f0..1f754a403 100644 --- a/lib/src/phy/rf/rf_imp.c +++ b/lib/src/phy/rf/rf_imp.c @@ -94,11 +94,6 @@ const char* srsran_rf_get_devname(srsran_rf_t* rf) int srsran_rf_open_devname(srsran_rf_t* rf, const char* devname, char* args, uint32_t nof_channels) { - if (srsran_rf_load_plugins() != SRSRAN_SUCCESS) { - ERROR("Failed to load RF plugins"); - return SRSRAN_ERROR; - } - rf->thread_gain_run = false; bool no_rf_devs_detected = true; @@ -482,3 +477,11 @@ int srsran_rf_load_plugins() #endif /* ENABLE_RF_PLUGINS */ return SRSRAN_SUCCESS; } + +// Search and load plugins when this library is loaded (shared) or right before main (static) +void __attribute__((constructor)) init() +{ + if (srsran_rf_load_plugins() != SRSRAN_SUCCESS) { + ERROR("Failed to load RF plugins"); + } +} diff --git a/lib/src/phy/rf/rf_zmq_test.c b/lib/src/phy/rf/rf_zmq_test.c index be42022e5..70d5704a5 100644 --- a/lib/src/phy/rf/rf_zmq_test.c +++ b/lib/src/phy/rf/rf_zmq_test.c @@ -233,7 +233,6 @@ int param_test(const char* args_param, const int num_channels) int main() { - srsran_rf_load_plugins(); // // two Rx ports // if (param_test("rx_port=ipc://dl0,rx_port1=ipc://dl1", 2)) { // fprintf(stderr, "Param test failed!\n");