mirror of https://gerrit.osmocom.org/libosmocore
core: fix wrong logic in _osmo_it_q_dequeue()
If the given queue is empty, queue->list.next points to &queue->list. Current implementation would call llist_del() on the queue's llist_head, decrement queue->current_length (which will be 0), and return a pointer to &queue->list to the caller. This is completely wrong. - Use the existing item_dequeue(), which does exactly what we need. - Do not decrement the current_length if nothing was dequeued. - Uncomment code in the unit test, we should not crash anymore. Change-Id: I63094df73b166b549616c869ad908e9f4f7d46d1 Fixes: CID#336557
This commit is contained in:
parent
09c8bfce07
commit
9c972934f9
|
@ -245,7 +245,7 @@ int _osmo_it_q_enqueue(struct osmo_it_q *queue, struct llist_head *item)
|
|||
|
||||
/*! Thread-safe de-queue from an inter-thread message queue.
|
||||
* \param[in] queue Inter-thread queue from which to dequeue
|
||||
* \returns dequeued message buffer; NULL if none available
|
||||
* \returns llist_head of dequeued message; NULL if none available
|
||||
*/
|
||||
struct llist_head *_osmo_it_q_dequeue(struct osmo_it_q *queue)
|
||||
{
|
||||
|
@ -254,12 +254,9 @@ struct llist_head *_osmo_it_q_dequeue(struct osmo_it_q *queue)
|
|||
|
||||
pthread_mutex_lock(&queue->mutex);
|
||||
|
||||
if (llist_empty(&queue->list))
|
||||
l = NULL;
|
||||
l = queue->list.next;
|
||||
OSMO_ASSERT(l);
|
||||
llist_del(l);
|
||||
queue->current_length--;
|
||||
l = item_dequeue(&queue->list);
|
||||
if (l != NULL)
|
||||
queue->current_length--;
|
||||
|
||||
pthread_mutex_unlock(&queue->mutex);
|
||||
|
||||
|
|
|
@ -81,11 +81,9 @@ static void tc_enqueue_dequeue(void)
|
|||
q1 = osmo_it_q_alloc(OTC_GLOBAL, "q1", 12, NULL, NULL);
|
||||
OSMO_ASSERT(q1);
|
||||
|
||||
#if 0
|
||||
printf("try dequeueing from an empty queue\n");
|
||||
osmo_it_q_dequeue(q1, &item, list);
|
||||
OSMO_ASSERT(item == NULL);
|
||||
#endif
|
||||
|
||||
printf("adding queue entries up to the limit\n");
|
||||
for (unsigned int i = 0; i < qlen; i++) {
|
||||
|
@ -101,11 +99,9 @@ static void tc_enqueue_dequeue(void)
|
|||
talloc_free(item);
|
||||
}
|
||||
|
||||
#if 0
|
||||
printf("try dequeueing from an empty queue\n");
|
||||
osmo_it_q_dequeue(q1, &item, list);
|
||||
OSMO_ASSERT(item == NULL);
|
||||
#endif
|
||||
|
||||
osmo_it_q_destroy(q1);
|
||||
}
|
||||
|
|
|
@ -11,8 +11,10 @@ attempting to add more than the limit
|
|||
|
||||
== Entering test case tc_enqueue_dequeue
|
||||
allocating q1
|
||||
try dequeueing from an empty queue
|
||||
adding queue entries up to the limit
|
||||
removing queue entries up to the limit
|
||||
try dequeueing from an empty queue
|
||||
|
||||
== Entering test case tc_eventfd
|
||||
allocating q1
|
||||
|
|
Loading…
Reference in New Issue