From 3173dedf0a3804985f252e72b4b768d6566d1827 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Wed, 9 Jun 2021 16:39:54 +0200 Subject: [PATCH] ue_stack_lte: make sure to execute stack commands on Stack thread some commands were executed from the calling thread which may lead to concurrent access to members. Detected by TSAN. The patch moves all remaining calls (the majority was alread moved) to the Stack task queue. --- srsue/src/stack/ue_stack_lte.cc | 49 ++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/srsue/src/stack/ue_stack_lte.cc b/srsue/src/stack/ue_stack_lte.cc index 94adee7dd..56f164c1d 100644 --- a/srsue/src/stack/ue_stack_lte.cc +++ b/srsue/src/stack/ue_stack_lte.cc @@ -271,35 +271,46 @@ bool ue_stack_lte::switch_on() bool ue_stack_lte::switch_off() { - // generate detach request with switch-off flag - nas.switch_off(); + if (running) { + ue_task_queue.try_push([this]() { + // generate detach request with switch-off flag + nas.switch_off(); - // wait for max. 5s for it to be sent (according to TS 24.301 Sec 25.5.2.2) - int cnt = 0, timeout_ms = 5000; - while (not rrc.srbs_flushed() && ++cnt <= timeout_ms) { - std::this_thread::sleep_for(std::chrono::milliseconds(1)); + // wait for max. 5s for it to be sent (according to TS 24.301 Sec 25.5.2.2) + int cnt = 0, timeout_ms = 5000; + while (not rrc.srbs_flushed() && ++cnt <= timeout_ms) { + std::this_thread::sleep_for(std::chrono::milliseconds(1)); + } + if (not rrc.srbs_flushed()) { + srslog::fetch_basic_logger("NAS").warning("Detach couldn't be sent after %dms.", timeout_ms); + } + }); } - bool detach_sent = true; - if (not rrc.srbs_flushed()) { - srslog::fetch_basic_logger("NAS").warning("Detach couldn't be sent after %dms.", timeout_ms); - detach_sent = false; - } - - return detach_sent; + return true; } bool ue_stack_lte::enable_data() { - // perform attach request - srsran::console("Turning off airplane mode.\n"); - return nas.enable_data(); + if (running) { + ue_task_queue.try_push([this]() { + // perform attach request + srsran::console("Turning off airplane mode.\n"); + nas.enable_data(); + }); + } + return true; } bool ue_stack_lte::disable_data() { - // generate detach request - srsran::console("Turning on airplane mode.\n"); - return nas.disable_data(); + if (running) { + ue_task_queue.try_push([this]() { + // generate detach request + srsran::console("Turning on airplane mode.\n"); + nas.disable_data(); + }); + } + return true; } bool ue_stack_lte::start_service_request()