Added mutex and condition_variable to srsUE's nas_test to avoid race condition on thread initialization.

master
Pedro Alvarez 4 years ago committed by Andre Puschmann
parent 324cb80cac
commit 6929883649

@ -164,7 +164,10 @@ public:
void run_thread() void run_thread()
{ {
std::unique_lock<std::mutex> lk(init_mutex);
running = true; running = true;
init_cv.notify_all();
lk.unlock();
while (running) { while (running) {
task_sched.tic(); task_sched.tic();
task_sched.run_pending_tasks(); task_sched.run_pending_tasks();
@ -173,6 +176,10 @@ public:
} }
void stop() void stop()
{ {
std::unique_lock<std::mutex> lk(init_mutex);
while (not running) {
init_cv.wait(lk);
}
running = false; running = false;
wait_thread_finish(); wait_thread_finish();
} }
@ -180,6 +187,8 @@ public:
pdcp_interface_gw* pdcp = nullptr; pdcp_interface_gw* pdcp = nullptr;
srsue::nas* nas = nullptr; srsue::nas* nas = nullptr;
bool running = false; bool running = false;
std::mutex init_mutex;
std::condition_variable init_cv;
}; };
class gw_dummy : public gw_interface_nas, public gw_interface_pdcp class gw_dummy : public gw_interface_nas, public gw_interface_pdcp
@ -310,7 +319,6 @@ int mme_attach_request_test()
gw.init(gw_args, g_logger, &stack); gw.init(gw_args, g_logger, &stack);
stack.init(&nas); stack.init(&nas);
usleep(5000); // Wait for stack to initialize before stoping it.
// trigger test // trigger test
stack.switch_on(); stack.switch_on();
stack.stop(); stack.stop();

Loading…
Cancel
Save