Skip to content

Commit

Permalink
Linux platform: fix polling queue (#12)
Browse files Browse the repository at this point in the history
In linux platform, one thread polls for indication
and another thread handle them.
The code to determine the number of free elements in the
queue was buggy resulting in polling too much indication
without being able to store them before dispatching them.
  • Loading branch information
GwendalRaoul authored and saarinenv committed Jun 25, 2019
1 parent 1adb7f3 commit aa979ca
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lib/platform/linux/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,18 +177,31 @@ static void * poll_for_indication(void * unused)
/* Ask for maximum room in buffer queue and less than MAX */
if (!m_queue_empty && (m_ind_queue_write == m_ind_queue_read))
{
// Queue is FULL
// Queue is FULL, wait for POLLING INTERVALL to give some
// time for the dispatching thread to handle them
LOGW("Queue is full, do not poll\n");
wait_before_next_polling_ms = POLLING_INTERVAL_MS;
continue;
}
else if (m_queue_empty)
{
// Queue is empty
free_buffer_room = MAX_NUMBER_INDICATION_QUEUE;
}
else
{
free_buffer_room = m_ind_queue_write - m_ind_queue_read % MAX_NUMBER_INDICATION_QUEUE;
// Queue has elements, determine the number of free buffers
if (m_ind_queue_write > m_ind_queue_read)
{
free_buffer_room = MAX_NUMBER_INDICATION_QUEUE -
(m_ind_queue_write - m_ind_queue_read);
}
else
{
free_buffer_room = m_ind_queue_read - m_ind_queue_write;
}
}

max_num_indication = free_buffer_room > MAX_NUMBER_INDICATION ?
MAX_NUMBER_INDICATION :
free_buffer_room;
Expand Down

0 comments on commit aa979ca

Please sign in to comment.