From b8f674f5b6e95cb8f2a0f44be3f3601a3e7bedc9 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Wed, 12 Jun 2013 16:18:32 +0200 Subject: [PATCH] fix context switch in lpm_sleep --- cpu/native/lpm_cpu.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/cpu/native/lpm_cpu.c b/cpu/native/lpm_cpu.c index f621c9606..45a5e01bc 100644 --- a/cpu/native/lpm_cpu.c +++ b/cpu/native/lpm_cpu.c @@ -46,11 +46,19 @@ void _native_lpm_sleep() retval = select(1, &_native_uart_rfds, NULL, NULL, NULL); DEBUG("_native_lpm_sleep: retval: %i\n", retval); if (retval != -1) { - DEBUG("\n\n\t\treturn from syscall, calling _native_handle_uart0_input\n\n"); + /* uart ready, swap to ISR context and handle input */ + makecontext(_native_isr_ctx, _native_handle_uart0_input, 0); + swapcontext((ucontext_t*)(active_thread->sp), _native_isr_ctx); + } + else if ((retval == -1) && (errno == EINTR)) { + /* TODO: reevaluate and merge with above branch + * IF any thread except the idle thread uses lpm_set this could make sense... */ + /* select interrupted by signal swap to ISR context and handle input */ + DEBUG("\n\n\t\treturn from interrupted syscall, swapping context and calling _native_handle_uart0_input\n\n"); makecontext(_native_isr_ctx, _native_handle_uart0_input, 0); swapcontext(_native_cur_ctx, _native_isr_ctx); } - else if (errno != EINTR) { + else { err(1, "lpm_set(): select()"); } #else