From 97ddf5ea28e6bac5a2ff037f34a3a568dd067913 Mon Sep 17 00:00:00 2001
From: Cedric Roux <cedric.roux@eurecom.fr>
Date: Mon, 27 Aug 2018 17:32:00 +0200
Subject: [PATCH] basic simulator: bugfix: wait for synch ready at the right
 time

Before this commit we were checking for UE->is_synchronized == 0
then we were waiting for a potentially active synch routine to
finish and then we were starting the synch routine again but the
synch routine that was running may have set UE->is_synchronized
to 1. This was leading to various problems, most notably the following
message repeated over and over in the UE log and the UE unable to
connect properly:

    [RRC]  [UE 0] Frame 377: OUT OF SYNC FROM eNB 0 (T310 active 0 : T310 0, N310 345, N311 0)

So let's wait for a potentially active synch routine to finish
before anything else.
---
 targets/RT/USER/lte-ue.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/targets/RT/USER/lte-ue.c b/targets/RT/USER/lte-ue.c
index ab84249f9f..fbf0eff1cd 100644
--- a/targets/RT/USER/lte-ue.c
+++ b/targets/RT/USER/lte-ue.c
@@ -1459,18 +1459,19 @@ void *UE_thread(void *arg) {
 
 
   while (!oai_exit) {
+#if BASIC_SIMULATOR
+    while (!(UE->proc.instance_cnt_synch < 0)) {
+      printf("ue sync not ready\n");
+      usleep(500*1000);
+    }
+#endif
+
     AssertFatal ( 0== pthread_mutex_lock(&UE->proc.mutex_synch), "");
     int instance_cnt_synch = UE->proc.instance_cnt_synch;
     int is_synchronized    = UE->is_synchronized;
     AssertFatal ( 0== pthread_mutex_unlock(&UE->proc.mutex_synch), "");
 
     if (is_synchronized == 0) {
-#if BASIC_SIMULATOR
-      while (!((instance_cnt_synch = UE->proc.instance_cnt_synch) < 0)) {
-        printf("ue sync not ready\n");
-        usleep(500*1000);
-      }
-#endif
       if (instance_cnt_synch < 0) {  // we can invoke the synch
 	// grab 10 ms of signal and wakeup synch thread
 	for (int i=0; i<UE->frame_parms.nb_antennas_rx; i++)
-- 
GitLab