Ensure trx_stop is called before trx_end

Make sure the radio libs are stopped before `end()` call. This allows
for a cleaner exit under most circumstances. Some libraries like zmq_radio
don't exit cleanly without it.
This commit is contained in:
Bartosz Podrygajlo
2026-04-22 22:34:02 +02:00
parent 9ef4efe10a
commit 384886ce48
4 changed files with 29 additions and 6 deletions
+17 -6
View File
@@ -131,13 +131,18 @@ void exit_function(const char *file, const char *function, const int line, const
printf("%s:%d %s() Exiting OAI softmodem: %s\n",file,line, function, s);
}
oai_exit = 1;
if (RC.ru == NULL)
exit(-1); // likely init not completed, prevent crash or hang, exit now...
for (ru_id=0; ru_id<RC.nb_RU; ru_id++) {
if (RC.ru[ru_id] && RC.ru[ru_id]->rfdevice.trx_end_func) {
if (RC.ru[ru_id] == NULL) {
continue;
}
if (RC.ru[ru_id]->ifdevice.trx_stop_func) {
RC.ru[ru_id]->ifdevice.trx_stop_func(&RC.ru[ru_id]->ifdevice);
RC.ru[ru_id]->ifdevice.trx_stop_func = NULL;
}
if (RC.ru[ru_id]->rfdevice.trx_end_func) {
if (RC.ru[ru_id]->rfdevice.trx_get_stats_func) {
RC.ru[ru_id]->rfdevice.trx_get_stats_func(&RC.ru[ru_id]->rfdevice);
RC.ru[ru_id]->rfdevice.trx_get_stats_func = NULL;
@@ -146,6 +151,10 @@ void exit_function(const char *file, const char *function, const int line, const
RC.ru[ru_id]->rfdevice.trx_end_func = NULL;
}
if (RC.ru[ru_id]->ifdevice.trx_stop_func) {
RC.ru[ru_id]->ifdevice.trx_stop_func(&RC.ru[ru_id]->ifdevice);
RC.ru[ru_id]->ifdevice.trx_stop_func = NULL;
}
if (RC.ru[ru_id] && RC.ru[ru_id]->ifdevice.trx_end_func) {
if (RC.ru[ru_id]->ifdevice.trx_get_stats_func) {
RC.ru[ru_id]->ifdevice.trx_get_stats_func(&RC.ru[ru_id]->ifdevice);
@@ -156,6 +165,8 @@ void exit_function(const char *file, const char *function, const int line, const
}
}
oai_exit = 1;
if (assert) {
abort();
} else {
@@ -358,9 +369,6 @@ int stop_L1(module_id_t gnb_id)
if (RC.nb_nr_L1_inst > 0)
stop_gNB(RC.nb_nr_L1_inst);
if (RC.nb_RU > 0)
stop_RU(RC.nb_RU);
/* stop trx devices, multiple carrier currently not supported by RU */
if (ru->rfdevice.trx_get_stats_func) {
ru->rfdevice.trx_get_stats_func(&ru->rfdevice);
@@ -378,6 +386,9 @@ int stop_L1(module_id_t gnb_id)
LOG_I(GNB_APP, "turned off RU ifdevice\n");
}
if (RC.nb_RU > 0)
stop_RU(RC.nb_RU);
/* release memory used by the RU/gNB threads (incomplete), after all
* threads have been stopped (they partially use the same memory) */
for (int inst = 0; inst < RC.nb_RU; inst++) {