signal: change sig_waitTimeoutSignal() to accept custom timeout hook
authorarighi <arighi@38d2e660-2303-0410-9eaa-f027e97ec537>
Mon, 14 Mar 2011 12:01:10 +0000 (12:01 +0000)
committerarighi <arighi@38d2e660-2303-0410-9eaa-f027e97ec537>
Mon, 14 Mar 2011 12:01:10 +0000 (12:01 +0000)
Change sig_waitTimeoutSignal() to accept a function hook to be called
when the timeout expires, instead of always using the default timeout
callback.

This makes possible to specify custom timeout actions, i.e. changing the
state of other dependent or derived objects (e.g., events).

git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4768 38d2e660-2303-0410-9eaa-f027e97ec537

bertos/kern/signal.c
bertos/kern/signal.h

index 26805b5fdd79328e0de5b6a3d0283d7813712b47..2b3a191fe06b7a94194d45e9adc142b511cffcf2 100644 (file)
@@ -191,13 +191,9 @@ sigmask_t sig_waitSignal(Signal *s, sigmask_t sigs)
 #if CONFIG_TIMER_EVENTS
 
 #include <drv/timer.h>
-/**
- * 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).
- * \return the signal(s) that have awoken the process.
- * \note Caller must check return value to check which signal awoke the process.
- */
-sigmask_t sig_waitTimeoutSignal(Signal *s, sigmask_t sigs, ticks_t timeout)
+
+sigmask_t sig_waitTimeoutSignal(Signal *s, sigmask_t sigs, ticks_t timeout,
+                               Hook func, iptr_t data)
 {
        Timer t;
        sigmask_t res;
@@ -208,7 +204,10 @@ sigmask_t sig_waitTimeoutSignal(Signal *s, sigmask_t sigs, ticks_t timeout)
        /* IRQ are needed to run timer */
        ASSERT(IRQ_ENABLED());
 
-       timer_set_event_signal(&t, proc_current(), SIG_TIMEOUT);
+       if (func)
+               timer_setSoftint(&t, func, data);
+       else
+               timer_set_event_signal(&t, proc_current(), SIG_TIMEOUT);
        timer_setDelay(&t, timeout);
        timer_add(&t);
        res = sig_waitSignal(s, SIG_TIMEOUT | sigs);
index c613604134b6af8174b97f70a71fe618e42a146d..8821cfd9c08d07521d965bdab619e1324005468d 100644 (file)
@@ -147,12 +147,20 @@ INLINE sigmask_t sig_wait(sigmask_t sigs)
        return sig_waitSignal(&proc->sig, sigs);
 }
 
-sigmask_t sig_waitTimeoutSignal(Signal *s, sigmask_t sigs, ticks_t timeout);
+sigmask_t sig_waitTimeoutSignal(Signal *s, sigmask_t sigs, ticks_t timeout,
+                               Hook func, iptr_t data);
 
+/**
+ * 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).
+ * \return the signal(s) that have awoken the process.
+ * \note Caller must check return value to check which signal awoke the process.
+ */
 INLINE sigmask_t sig_waitTimeout(sigmask_t sigs, ticks_t timeout)
 {
        Process *proc = proc_current();
-       return sig_waitTimeoutSignal(&proc->sig, sigs, timeout);
+       return sig_waitTimeoutSignal(&proc->sig, sigs, timeout,
+                       NULL, NULL);
 }
 
 #endif /* CONFIG_KERN_SIGNALS */