srsLTE/lib/src/mac/pdu_queue.cc

98 lines
2.2 KiB
C++
Raw Normal View History

/**
*
* \section COPYRIGHT
*
* Copyright 2013-2020 Software Radio Systems Limited
*
* By using this file, you agree to the terms and conditions set
* forth in the LICENSE file which can be found at the top level of
* the distribution.
*
*/
2020-04-21 12:53:37 -07:00
#include "srslte/mac/pdu_queue.h"
#include "srslte/common/log_helper.h"
namespace srslte {
void pdu_queue::init(process_callback* callback_, log_ref log_h_)
{
callback = callback_;
log_h = log_h_;
}
uint8_t* pdu_queue::request(uint32_t len)
{
if (len > MAX_PDU_LEN) {
2019-04-23 01:53:11 -07:00
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) {
if (log_h) {
log_h->error("Not enough buffers for MAC PDU\n");
}
2019-04-23 01:53:11 -07:00
ERROR("Not enough buffers for MAC PDU\n");
}
if ((void*)pdu->ptr != (void*)pdu) {
2019-04-23 01:53:11 -07:00
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)
{
if (!pool.deallocate((pdu_t*)pdu)) {
2017-10-06 05:33:22 -07:00
log_h->warning("Error deallocating from buffer pool in deallocate(): buffer not created in this pool.\n");
}
}
2019-04-23 01:53:11 -07:00
/* Demultiplexing of logical channels and dissassemble of MAC CE
* This function enqueues the packet and returns quicly because ACK
* deadline is important here.
*/
void pdu_queue::push(const uint8_t* ptr, uint32_t len, channel_t channel)
{
2018-03-05 05:33:51 -08:00
if (ptr) {
pdu_t* pdu = (pdu_t*)ptr;
pdu->len = len;
pdu->channel = channel;
2018-03-05 05:33:51 -08:00
pdu_q.push(pdu);
} else {
log_h->warning("Error pushing pdu: ptr is empty\n");
}
}
bool pdu_queue::process_pdus()
{
bool have_data = false;
uint32_t cnt = 0;
pdu_t* pdu;
while (pdu_q.try_pop(&pdu)) {
if (callback) {
2019-04-23 01:53:11 -07:00
callback->process_pdu(pdu->ptr, pdu->len, pdu->channel);
}
cnt++;
have_data = true;
}
if (cnt > 20) {
if (log_h) {
log_h->warning("PDU queue dispatched %d packets\n", cnt);
}
printf("Warning PDU queue dispatched %d packets\n", cnt);
}
return have_data;
}
void pdu_queue::reset()
{
pdu_t* pdu;
while (pdu_q.try_pop(&pdu)) {
// nop
}
}
} // namespace srslte