From 5999b0d3a5e8ad5c8863961de0464009f9190a30 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Mon, 28 Jun 2021 11:00:17 +0200 Subject: [PATCH] ue: move blocking wait for detach outside of stack class the thread sleep waiting for the UE release should not run on the stack thread. Move it to the UE class therefore. --- srsue/src/stack/ue_stack_lte.cc | 9 --------- srsue/src/ue.cc | 21 ++++++++++++++++++++- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/srsue/src/stack/ue_stack_lte.cc b/srsue/src/stack/ue_stack_lte.cc index 56f164c1d..4bef269a1 100644 --- a/srsue/src/stack/ue_stack_lte.cc +++ b/srsue/src/stack/ue_stack_lte.cc @@ -275,15 +275,6 @@ bool ue_stack_lte::switch_off() 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)); - } - if (not rrc.srbs_flushed()) { - srslog::fetch_basic_logger("NAS").warning("Detach couldn't be sent after %dms.", timeout_ms); - } }); } return true; diff --git a/srsue/src/ue.cc b/srsue/src/ue.cc index ac2ab2951..6e8914ff6 100644 --- a/srsue/src/ue.cc +++ b/srsue/src/ue.cc @@ -301,7 +301,26 @@ bool ue::switch_off() if (gw_inst) { gw_inst->stop(); } - return stack->switch_off(); + + // send switch off + stack->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_s = 5; + stack_metrics_t metrics = {}; + stack->get_metrics(&metrics); + + while (metrics.rrc.state != RRC_STATE_IDLE && ++cnt <= timeout_s) { + std::this_thread::sleep_for(std::chrono::seconds(1)); + stack->get_metrics(&metrics); + } + + if (metrics.rrc.state != RRC_STATE_IDLE) { + srslog::fetch_basic_logger("NAS").warning("Detach couldn't be sent after %ds.", timeout_s); + return false; + } + + return true; } void ue::start_plot()