diff options
author | Keith Packard <keithp@keithp.com> | 2013-03-24 15:00:20 -0700 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2013-03-31 12:24:24 -0700 |
commit | 4f1f3e836393304434130d362771a39f6f8f859a (patch) | |
tree | 5655f7ae7aa252a96aa585e3aee47b1b57a8fc9a /src/core/ao_stdio.c | |
parent | 7afcec1a1dce140dfa569469df4ef42ed407a742 (diff) |
altos: Do not release interrupts from any pollchar function
getchar relies on interrupts being blocked across the pollchar calls
and into the sleep call or it may go to sleep with data pending.
This prefixes all pollchar functions with _ to indicate that they are
to be called with interrupts blocked and eliminates all interrupt
manipulation calls from within the pollchar functions.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src/core/ao_stdio.c')
-rw-r--r-- | src/core/ao_stdio.c | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/src/core/ao_stdio.c b/src/core/ao_stdio.c index 1748dfe8..977d74b1 100644 --- a/src/core/ao_stdio.c +++ b/src/core/ao_stdio.c @@ -99,20 +99,21 @@ char getchar(void) __reentrant { int c; - ao_arch_critical( - int8_t stdio = ao_cur_stdio; + int8_t stdio; - for (;;) { - c = ao_stdios[stdio].pollchar(); - if (c != AO_READ_AGAIN) - break; - if (++stdio == ao_num_stdios) - stdio = 0; - if (stdio == ao_cur_stdio) - ao_sleep(&ao_stdin_ready); - } - ao_cur_stdio = stdio; - ); + ao_arch_block_interrupts(); + stdio = ao_cur_stdio; + for (;;) { + c = ao_stdios[stdio]._pollchar(); + if (c != AO_READ_AGAIN) + break; + if (++stdio == ao_num_stdios) + stdio = 0; + if (stdio == ao_cur_stdio) + ao_sleep(&ao_stdin_ready); + } + ao_cur_stdio = stdio; + ao_arch_release_interrupts(); return c; } @@ -123,13 +124,13 @@ ao_echo(void) } int8_t -ao_add_stdio(int (*pollchar)(void), +ao_add_stdio(int (*_pollchar)(void), void (*putchar)(char), void (*flush)(void)) __reentrant { if (ao_num_stdios == AO_NUM_STDIOS) ao_panic(AO_PANIC_STDIO); - ao_stdios[ao_num_stdios].pollchar = pollchar; + ao_stdios[ao_num_stdios]._pollchar = _pollchar; ao_stdios[ao_num_stdios].putchar = putchar; ao_stdios[ao_num_stdios].flush = flush; ao_stdios[ao_num_stdios].echo = 1; |