From 8591049e928da086cfb599b08799a1d46f992c18 Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Mon, 5 Mar 2018 14:33:51 +0100 Subject: [PATCH] Added mutex to ul/dl harq reset --- lib/src/common/pdu_queue.cc | 12 ++++++++---- srsue/hdr/mac/dl_harq.h | 16 +++++++++++++++- srsue/hdr/mac/ul_harq.h | 11 ++++++++++- srsue/src/upper/rrc.cc | 2 ++ 4 files changed, 35 insertions(+), 6 deletions(-) diff --git a/lib/src/common/pdu_queue.cc b/lib/src/common/pdu_queue.cc index 3a116e641..061433033 100644 --- a/lib/src/common/pdu_queue.cc +++ b/lib/src/common/pdu_queue.cc @@ -76,10 +76,14 @@ void pdu_queue::deallocate(uint8_t* pdu) */ void pdu_queue::push(uint8_t *ptr, uint32_t len, uint32_t tstamp) { - pdu_t *pdu = (pdu_t*) ptr; - pdu->len = len; - pdu->tstamp = tstamp; - pdu_q.push(pdu); + if (ptr) { + pdu_t *pdu = (pdu_t*) ptr; + pdu->len = len; + pdu->tstamp = tstamp; + pdu_q.push(pdu); + } else { + log_h->warning("Error pushing pdu: ptr is empty\n"); + } } bool pdu_queue::process_pdus() diff --git a/srsue/hdr/mac/dl_harq.h b/srsue/hdr/mac/dl_harq.h index 261fb0d41..982a6eac6 100644 --- a/srsue/hdr/mac/dl_harq.h +++ b/srsue/hdr/mac/dl_harq.h @@ -196,6 +196,8 @@ private: is_initiated = false; ack = false; bzero(&cur_grant, sizeof(Tgrant)); + + pthread_mutex_init(&mutex, NULL); } ~dl_tb_process() { @@ -220,16 +222,23 @@ private: } void reset(void) { + pthread_mutex_lock(&mutex); is_first_tb = true; ack = false; - payload_buffer_ptr = NULL; + if (payload_buffer_ptr) { + harq_entity->demux_unit->deallocate(payload_buffer_ptr); + } bzero(&cur_grant, sizeof(Tgrant)); if (is_initiated) { srslte_softbuffer_rx_reset(&softbuffer); } + pthread_mutex_unlock(&mutex); } void new_grant_dl(Tgrant grant, Taction *action) { + + pthread_mutex_lock(&mutex); + // Compute RV for BCCH when not specified in PDCCH format if (pid == HARQ_BCCH_PID && grant.rv[tid] == -1) { uint32_t k; @@ -271,6 +280,7 @@ private: if (!action->payload_ptr[tid]) { action->decode_enabled[tid] = false; Error("Can't get a buffer for TBS=%d\n", cur_grant.n_bytes[tid]); + pthread_mutex_unlock(&mutex); return; } action->decode_enabled[tid]= true; @@ -299,6 +309,8 @@ private: Debug("Generating ACK\n"); } } + + pthread_mutex_unlock(&mutex); } void tb_decoded(bool ack_) { @@ -364,6 +376,8 @@ private: return is_new_transmission; } + pthread_mutex_t mutex; + bool is_initiated; dl_harq_entity *harq_entity; srslte::log *log_h; diff --git a/srsue/hdr/mac/ul_harq.h b/srsue/hdr/mac/ul_harq.h index 5c44a222e..4ab4756b9 100644 --- a/srsue/hdr/mac/ul_harq.h +++ b/srsue/hdr/mac/ul_harq.h @@ -159,6 +159,8 @@ private: tti_last_tx = 0; payload_buffer = NULL; bzero(&cur_grant, sizeof(Tgrant)); + + pthread_mutex_init(&mutex, NULL); } ~ul_harq_process() @@ -193,17 +195,21 @@ private: void reset() { + pthread_mutex_lock(&mutex); current_tx_nb = 0; current_irv = 0; tti_last_tx = 0; is_grant_configured = false; bzero(&cur_grant, sizeof(Tgrant)); + pthread_mutex_unlock(&mutex); } void reset_ndi() { cur_grant.ndi[0] = false; } void run_tti(uint32_t tti_tx, Tgrant *grant, bool *ack, Taction* action) { + pthread_mutex_lock(&mutex); + if (ack) { if (grant) { if (grant->ndi[0] == get_ndi() && grant->phy_grant.ul.mcs.tbs != 0) { @@ -276,6 +282,8 @@ private: } harq_entity->pcap->write_ul_crnti(pdu_ptr, grant->n_bytes[0], grant->rnti, get_nof_retx(), tti_tx); } + + pthread_mutex_unlock(&mutex); } uint32_t get_rv() @@ -304,7 +312,8 @@ private: bool is_msg3; bool is_initiated; uint32_t tti_last_tx; - + + pthread_mutex_t mutex; const static int payload_buffer_len = 128*1024; uint8_t *payload_buffer; diff --git a/srsue/src/upper/rrc.cc b/srsue/src/upper/rrc.cc index 8ffdc1868..f2373ce2c 100644 --- a/srsue/src/upper/rrc.cc +++ b/srsue/src/upper/rrc.cc @@ -768,6 +768,8 @@ void rrc::earfcn_end() { // If searching for PLMN, indicate NAS we scanned all frequencies if (state == RRC_STATE_PLMN_SELECTION) { nas->plmn_search_end(); + } else if (state == RRC_STATE_CONNECTED) { + leave_connected(); } }