diff --git a/lib/src/mac/pdu_queue.cc b/lib/src/mac/pdu_queue.cc index bd8628b0e..fa8b201ca 100644 --- a/lib/src/mac/pdu_queue.cc +++ b/lib/src/mac/pdu_queue.cc @@ -27,19 +27,21 @@ uint8_t* pdu_queue::request(uint32_t len) ERROR("Error request buffer of invalid size %d. Max bytes %d\n", len, MAX_PDU_LEN); return NULL; } - pdu_t* pdu = pool.allocate("pdu_queue::request", true); - if (!pdu) { + // This function must be non-blocking. In case we run out of buffers, it shall handle the error properly + pdu_t* pdu = pool.allocate("pdu_queue::request", false); + if (pdu) { + if ((void*)pdu->ptr != (void*)pdu) { + ERROR("Fatal error in memory alignment in struct pdu_queue::pdu_t\n"); + exit(-1); + } + return pdu->ptr; + } else { if (log_h) { log_h->error("Not enough buffers for MAC PDU\n"); } ERROR("Not enough buffers for MAC PDU\n"); + return nullptr; } - if ((void*)pdu->ptr != (void*)pdu) { - ERROR("Fatal error in memory alignment in struct pdu_queue::pdu_t\n"); - exit(-1); - } - - return pdu->ptr; } void pdu_queue::deallocate(const uint8_t* pdu) diff --git a/srsenb/src/stack/mac/mac.cc b/srsenb/src/stack/mac/mac.cc index 84d527614..2b7abc3b4 100644 --- a/srsenb/src/stack/mac/mac.cc +++ b/srsenb/src/stack/mac/mac.cc @@ -907,7 +907,11 @@ int mac::get_ul_sched(uint32_t tti_tx_ul, ul_sched_list_t& ul_sched_res_list) srslte_softbuffer_rx_reset_tbs(phy_ul_sched_res->pusch[n].softbuffer_rx, sched_result.pusch[i].tbs * 8); } phy_ul_sched_res->pusch[n].data = ue_db[rnti]->request_buffer(sched_result.pusch[i].tbs); - phy_ul_sched_res->nof_grants++; + if (phy_ul_sched_res->pusch[n].data) { + phy_ul_sched_res->nof_grants++; + } else { + Error("Grant for rnti=0x%x could not be allocated due to lack of buffers\n", rnti); + } n++; } else { Warning("Invalid UL scheduling result. User 0x%x does not exist\n", rnti);