X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;ds=sidebyside;f=bertos%2Fkern%2Fsignal.c;h=948d68f1d814c687e8edb805b047da4596975242;hb=84c1846c483f7ddad5804c555c7e0d207f8d1ddc;hp=4333fa7937fe251a91ee2a0c5bdb1e4120d35006;hpb=cfa8814ca45e8bae9b36713bc534ecb581834016;p=bertos.git diff --git a/bertos/kern/signal.c b/bertos/kern/signal.c index 4333fa79..948d68f1 100644 --- a/bertos/kern/signal.c +++ b/bertos/kern/signal.c @@ -92,7 +92,7 @@ * - Do not sleep between starting the asynchronous task that will fire * SIG_SINGLE, and the call to sig_wait(). * - Do not call system functions that may implicitly sleep, such as - * timer_delayTickes(). + * timer_delayTicks(). * * \version $Id$ * \author Bernie Innocenti @@ -100,8 +100,9 @@ #include "signal.h" +#include #include -#include +#include #include #include @@ -110,6 +111,7 @@ /** * Check if any of the signals in \a sigs has occurred and clear them. + * * \return the signals that have occurred. */ sigmask_t sig_check(sigmask_t sigs) @@ -135,16 +137,23 @@ sigmask_t sig_wait(sigmask_t sigs) sigmask_t result; cpuflags_t flags; + /* Sleeping with IRQs disabled or preemption forbidden is illegal */ + IRQ_ASSERT_ENABLED(); + + #if CONFIG_KERN_PREEMPT + ASSERT(preempt_forbid_cnt == 0); + #endif + /* * This is subtle: there's a race condition where a concurrent - * process or an interrupt calls sig_signal() to set a bit in - * out sig_recv just after we have checked for it, but before - * we've set sig_wait to tell them we want to be awaken. + * process or an interrupt may call sig_signal() to set a bit in + * Process.sig_recv just after we have checked for it, but before + * we've set Process.sig_wait to let them know we want to be awaken. * - * In this case, we'd deadlock with the signal bit already - * set and the process never being reinserted into the ready - * list. + * In this case, we'd deadlock with the signal bit already set + * and the process never being reinserted into the ready list. */ + // FIXME: just use IRQ_DISABLE() here IRQ_SAVE_DISABLE(flags); /* Loop until we get at least one of the signals */ @@ -157,13 +166,13 @@ sigmask_t sig_wait(sigmask_t sigs) CurrentProcess->sig_wait = sigs; /* - * Go to sleep and proc_schedule() another process. + * Go to sleep and proc_switch() to another process. * - * We re-enable IRQs because proc_schedule() does not + * We re-enable IRQs because proc_switch() does not * guarantee to save and restore the interrupt mask. */ IRQ_RESTORE(flags); - proc_schedule(); + proc_switch(); IRQ_SAVE_DISABLE(flags); /* @@ -183,6 +192,9 @@ sigmask_t sig_wait(sigmask_t sigs) return result; } +#if CONFIG_TIMER_EVENTS + +#include /** * Sleep until any of the signals in \a sigs or \a timeout ticks elapse. * If the timeout elapse a SIG_TIMEOUT is added to the received signal(s). @@ -213,6 +225,8 @@ sigmask_t sig_waitTimeout(sigmask_t sigs, ticks_t timeout) return res; } +#endif // CONFIG_TIMER_EVENTS + /** * Send the signals \a sigs to the process \a proc.