Skip to content
Snippets Groups Projects
Commit 125d9e35 authored by Gregory Nutt's avatar Gregory Nutt
Browse files

Fix a cornercase problem in in the UART simulation

parent 3f0e65a3
No related branches found
No related tags found
No related merge requests found
......@@ -232,30 +232,37 @@ int simuart_getc(void)
int index;
int ch;
/* Locking the scheduler should eliminate the race conditions in the
* unlikely case of mutliple reading threads.
*/
sched_lock();
for (;;)
{
/* Wait for a byte to become available */
simuart_wait();
/* The UART buffer show be non-empty... check anyway */
if (g_uarthead != g_uarttail)
while (g_uarthead == g_uarttail)
{
/* Take the next byte from the tail of the buffer */
simuart_wait();
}
index = g_uarttail;
ch = (int)g_uartbuffer[index];
/* Increment the tai index (with wrapping) */
/* The UART buffer is non-empty... Take the next byte from the tail
* of the buffer.
*/
if (++index >= SIMUART_BUFSIZE)
{
index = 0;
}
index = g_uarttail;
ch = (int)g_uartbuffer[index];
/* Increment the tai index (with wrapping) */
g_uarttail = index;
return ch;
if (++index >= SIMUART_BUFSIZE)
{
index = 0;
}
g_uarttail = index;
sched_unlock();
return ch;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment