From d2daa68ae0b51f6ea8715772d8ed51cd572eadfd Mon Sep 17 00:00:00 2001
From: Lionel Gauthier <lionel.gauthier@eurecom.fr>
Date: Tue, 2 Dec 2014 10:05:41 +0000
Subject: [PATCH] But mutex on dar buffer, tested RTAI, but missed slot can
 occur, because phy rx and tx threads stimulate code with dar buffer, other
 solutions can be implemented.

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@6146 818b1a75-f10b-46b9-bf7c-635c3b92a50f
---
 openair2/LAYER2/RLC/UM_v9.3.0/rlc_um_control_primitives.c | 5 +++--
 openair2/LAYER2/RLC/UM_v9.3.0/rlc_um_control_primitives.h | 2 +-
 openair2/LAYER2/RLC/UM_v9.3.0/rlc_um_dar.c                | 8 +++++++-
 openair2/LAYER2/RLC/UM_v9.3.0/rlc_um_entity.h             | 3 +++
 4 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/openair2/LAYER2/RLC/UM_v9.3.0/rlc_um_control_primitives.c b/openair2/LAYER2/RLC/UM_v9.3.0/rlc_um_control_primitives.c
index 63ecce9b5a..f82c991e48 100755
--- a/openair2/LAYER2/RLC/UM_v9.3.0/rlc_um_control_primitives.c
+++ b/openair2/LAYER2/RLC/UM_v9.3.0/rlc_um_control_primitives.c
@@ -260,7 +260,7 @@ rlc_um_init (rlc_um_entity_t * const rlc_pP)
       rlc_pP->tx_sn_length          = 10;
       rlc_pP->tx_header_min_length_in_bytes = 2;
 
-
+      pthread_mutex_init(&rlc_pP->lock_dar_buffer, NULL);
       if (rlc_pP->dar_buffer == NULL) {
           rlc_pP->dar_buffer = calloc (1, 1024 * sizeof (void *));
       }
@@ -309,6 +309,7 @@ rlc_um_cleanup (rlc_um_entity_t * const rlc_pP)
       free (rlc_pP->dar_buffer);
       rlc_pP->dar_buffer = NULL;
   }
+  pthread_mutex_destroy(&rlc_pP->lock_dar_buffer);
   memset(rlc_pP, 0, sizeof(rlc_um_entity_t));
 }
 
@@ -382,7 +383,7 @@ void rlc_um_configure(
 }
 //-----------------------------------------------------------------------------
 void rlc_um_set_debug_infos(
-    rlc_um_entity_t *rlc_pP,
+    rlc_um_entity_t * const rlc_pP,
     const module_id_t      enb_module_idP,
     const module_id_t      ue_module_idP,
     const frame_t          frameP,
diff --git a/openair2/LAYER2/RLC/UM_v9.3.0/rlc_um_control_primitives.h b/openair2/LAYER2/RLC/UM_v9.3.0/rlc_um_control_primitives.h
index 19acd6bc64..2014045ec8 100644
--- a/openair2/LAYER2/RLC/UM_v9.3.0/rlc_um_control_primitives.h
+++ b/openair2/LAYER2/RLC/UM_v9.3.0/rlc_um_control_primitives.h
@@ -197,7 +197,7 @@ protected_rlc_um_control_primitives(void rlc_um_configure(
 * \param[in]  srb_flagP                 Flag to indicate signalling radio bearer (1) or data radio bearer (0).
 */
 protected_rlc_um_control_primitives(void rlc_um_set_debug_infos(
-    rlc_um_entity_t *rlcP,
+    rlc_um_entity_t * const rlcP,
     const module_id_t enb_module_idP,
     const module_id_t ue_module_idP,
     const frame_t frameP,
diff --git a/openair2/LAYER2/RLC/UM_v9.3.0/rlc_um_dar.c b/openair2/LAYER2/RLC/UM_v9.3.0/rlc_um_dar.c
index 074bdb5e3a..9ee376dc7b 100644
--- a/openair2/LAYER2/RLC/UM_v9.3.0/rlc_um_dar.c
+++ b/openair2/LAYER2/RLC/UM_v9.3.0/rlc_um_dar.c
@@ -763,7 +763,7 @@ void rlc_um_check_timer_dar_time_out(rlc_um_entity_t *rlc_pP, frame_t frameP, eN
                     rlc_pP->rb_id,
                     rlc_pP->vr_ur);
 #endif
-
+            pthread_mutex_lock(&rlc_pP->lock_dar_buffer);
             old_vr_ur   = rlc_pP->vr_ur;
 
             rlc_pP->vr_ur = rlc_pP->vr_ux;
@@ -803,6 +803,7 @@ void rlc_um_check_timer_dar_time_out(rlc_um_entity_t *rlc_pP, frame_t frameP, eN
 #endif
                 rlc_um_stop_and_reset_timer_reordering(rlc_pP, frameP);
             }
+            pthread_mutex_unlock(&rlc_pP->lock_dar_buffer);
         }
     }
     vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_UM_CHECK_TIMER_DAR_TIME_OUT,VCD_FUNCTION_OUT);
@@ -1055,6 +1056,8 @@ rlc_um_receive_process_dar (rlc_um_entity_t *rlc_pP, frame_t frameP, eNB_flag_t
     } else {
     	free_mem_block(pdu_mem_pP);
     }
+    pthread_mutex_lock(&rlc_pP->lock_dar_buffer);
+
     in_window = rlc_um_in_window(rlc_pP, frameP, rlc_pP->vr_uh - rlc_pP->rx_um_window_size, sn, rlc_pP->vr_ur);
 
 #if defined(DEBUG_RLC_PAYLOAD)
@@ -1082,6 +1085,7 @@ rlc_um_receive_process_dar (rlc_um_entity_t *rlc_pP, frame_t frameP, eNB_flag_t
         rlc_pP->stat_rx_data_bytes_out_of_window += tb_sizeP;
         free_mem_block(pdu_mem_pP);
         pdu_mem_pP = NULL;
+        pthread_mutex_unlock(&rlc_pP->lock_dar_buffer);
         vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_UM_RECEIVE_PROCESS_DAR, VCD_FUNCTION_OUT);
         return;
     }
@@ -1103,6 +1107,7 @@ rlc_um_receive_process_dar (rlc_um_entity_t *rlc_pP, frame_t frameP, eNB_flag_t
             rlc_pP->stat_rx_data_bytes_duplicate += tb_sizeP;
             free_mem_block(pdu_mem_pP);
             pdu_mem_pP = NULL;
+            pthread_mutex_unlock(&rlc_pP->lock_dar_buffer);
             vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_UM_RECEIVE_PROCESS_DAR, VCD_FUNCTION_OUT);
             return;
         }
@@ -1252,5 +1257,6 @@ rlc_um_receive_process_dar (rlc_um_entity_t *rlc_pP, frame_t frameP, eNB_flag_t
 #endif
         }
     }
+    pthread_mutex_unlock(&rlc_pP->lock_dar_buffer);
     vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_UM_RECEIVE_PROCESS_DAR, VCD_FUNCTION_OUT);
 }
diff --git a/openair2/LAYER2/RLC/UM_v9.3.0/rlc_um_entity.h b/openair2/LAYER2/RLC/UM_v9.3.0/rlc_um_entity.h
index b890822166..1109a9f7c6 100755
--- a/openair2/LAYER2/RLC/UM_v9.3.0/rlc_um_entity.h
+++ b/openair2/LAYER2/RLC/UM_v9.3.0/rlc_um_entity.h
@@ -106,6 +106,9 @@ typedef struct rlc_um_entity_s {
   mem_block_t      *output_sdu_in_construction;     /*!< \brief Memory area where a complete SDU is reassemblied before being send to upper layers. */
   sdu_size_t        output_sdu_size_to_write;       /*!< \brief Size of the reassemblied SDU. */
 
+
+  //pthread_spinlock_t lock_dar_buffer;
+  pthread_mutex_t      lock_dar_buffer;
   mem_block_t     **dar_buffer;                     /*!< \brief Array of rx PDUs. */
   list_t            pdus_from_mac_layer;            /*!< \brief Not Used. */
 
-- 
GitLab