Fix race condition when destroying the gnb stack class.

The gnb stack class could be destroyed concurrently while still running its task scheduler thread.
master
faluco 3 years ago committed by Andre Puschmann
parent 28bbaa7816
commit aa0c936f50

@ -106,6 +106,7 @@ public:
private: private:
void run_thread() final; void run_thread() final;
void tti_clock_impl(); void tti_clock_impl();
void stop_impl();
// args // args
gnb_stack_args_t args = {}; gnb_stack_args_t args = {};
@ -121,7 +122,7 @@ private:
static const int STACK_MAIN_THREAD_PRIO = 4; static const int STACK_MAIN_THREAD_PRIO = 4;
srsran::task_scheduler task_sched; srsran::task_scheduler task_sched;
srsran::task_multiqueue::queue_handle sync_task_queue, ue_task_queue, gtpu_task_queue, mac_task_queue, srsran::task_multiqueue::queue_handle sync_task_queue, ue_task_queue, gtpu_task_queue, mac_task_queue,
metrics_task_queue; metrics_task_queue, gnb_task_queue;
// metrics waiting condition // metrics waiting condition
std::mutex metrics_mutex; std::mutex metrics_mutex;

@ -35,6 +35,7 @@ gnb_stack_nr::gnb_stack_nr(srslog::sink& log_sink) :
gtpu_task_queue = task_sched.make_task_queue(); gtpu_task_queue = task_sched.make_task_queue();
mac_task_queue = task_sched.make_task_queue(); mac_task_queue = task_sched.make_task_queue();
metrics_task_queue = task_sched.make_task_queue(); metrics_task_queue = task_sched.make_task_queue();
gnb_task_queue = task_sched.make_task_queue();
} }
gnb_stack_nr::~gnb_stack_nr() gnb_stack_nr::~gnb_stack_nr()
@ -97,14 +98,22 @@ int gnb_stack_nr::init(const gnb_stack_args_t& args_,
void gnb_stack_nr::stop() void gnb_stack_nr::stop()
{ {
if (running) { if (running) {
gnb_task_queue.push([this]() { stop_impl(); });
wait_thread_finish();
}
}
void gnb_stack_nr::stop_impl()
{
rrc.stop(); rrc.stop();
pdcp.stop(); pdcp.stop();
mac.stop(); mac.stop();
task_sched.stop();
srsran::get_background_workers().stop(); srsran::get_background_workers().stop();
running = false; running = false;
} }
}
bool gnb_stack_nr::switch_on() bool gnb_stack_nr::switch_on()
{ {

Loading…
Cancel
Save