Commit b29fd449 authored by Melissa Elkadi's avatar Melissa Elkadi

Changed ul_tti_req queueing mechanism:

Instead of resetting queue when full,
take last item out.
parent 78253509
......@@ -752,18 +752,9 @@ static void enqueue_nr_nfapi_msg(void *buffer, ssize_t len, nfapi_p7_message_hea
{
LOG_D(NR_MAC, "We added UL_TTI_REQ to queue for sfn slot %d %d\n",
ul_tti_request->SFN, ul_tti_request->Slot);
if (!put_queue(&nr_wait_ul_tti_req_queue, ul_tti_request))
{
reset_queue(&nr_wait_ul_tti_req_queue);
if (!put_queue(&nr_wait_ul_tti_req_queue, ul_tti_request))
{
LOG_E(NR_PHY, "put_queue failed for nr_wait_ul_tti_req_queue.\n");
free(ul_tti_request);
ul_tti_request = NULL;
nfapi_nr_ul_tti_request_t *evicted_ul_tti_req = put_queue_replace(&nr_wait_ul_tti_req_queue, ul_tti_request);
free(evicted_ul_tti_req);
}
}
}
break;
}
......
......@@ -25,6 +25,34 @@ void reset_queue(queue_t *q)
}
}
void *put_queue_replace(queue_t *q, void *item)
{
assert(item != NULL);
if (pthread_mutex_lock(&q->mutex) != 0)
{
LOG_ERROR("put_queue: mutex_lock failed");
return false;
}
void *evicted = NULL;
if (q->num_items >= MAX_QUEUE_SIZE)
{
evicted = q->items[q->read_index];
assert(evicted != NULL);
q->items[q->read_index] = NULL;
q->read_index = (q->read_index + 1) % MAX_QUEUE_SIZE;
q->num_items--;
}
assert(q->items[q->write_index] == NULL);
q->items[q->write_index] = item;
q->write_index = (q->write_index + 1) % MAX_QUEUE_SIZE;
q->num_items++;
pthread_mutex_unlock(&q->mutex);
return evicted;
}
bool put_queue(queue_t *q, void *item)
{
assert(item != NULL);
......
......@@ -42,6 +42,7 @@ typedef struct queue_t
void init_queue(queue_t *q);
void reset_queue(queue_t *q);
void *put_queue_replace(queue_t *q, void *item);
bool put_queue(queue_t *q, void *item);
void *get_queue(queue_t *q);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment