Disable interrupts while reading from stdin
authorKeith Packard <keithp@keithp.com>
Wed, 5 May 2010 07:44:42 +0000 (00:44 -0700)
committerKeith Packard <keithp@keithp.com>
Wed, 5 May 2010 07:44:42 +0000 (00:44 -0700)
With multiple input source support, there is a lag between asking a
device if it has data and then waiting for more data to appear. If an
interrupt signalling additional input arrives in this interval, we'll
go to sleep with input available.

This patch uses a big hammer by just disabling interrupts for the
whole process.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/ao_stdio.c

index 8add30b842b04e1135a11201780a3d778da74671..045dff09f340e92b7b32b62ba2ceb914cfc2724f 100644 (file)
@@ -50,6 +50,7 @@ getchar(void) __reentrant
        char c;
        int8_t stdio = ao_cur_stdio;
 
        char c;
        int8_t stdio = ao_cur_stdio;
 
+       EA = 0;
        for (;;) {
                c = stdios[stdio].pollchar();
                if (c != AO_READ_AGAIN)
        for (;;) {
                c = stdios[stdio].pollchar();
                if (c != AO_READ_AGAIN)
@@ -59,6 +60,7 @@ getchar(void) __reentrant
                if (stdio == ao_cur_stdio)
                        ao_sleep(&ao_stdin_ready);
        }
                if (stdio == ao_cur_stdio)
                        ao_sleep(&ao_stdin_ready);
        }
+       EA = 1;
        ao_cur_stdio = stdio;
        return c;
 }
        ao_cur_stdio = stdio;
        return c;
 }