Add signal timeout (merge from digimod prj).
authorasterix <asterix@38d2e660-2303-0410-9eaa-f027e97ec537>
Wed, 16 Jan 2008 15:39:37 +0000 (15:39 +0000)
committerasterix <asterix@38d2e660-2303-0410-9eaa-f027e97ec537>
Wed, 16 Jan 2008 15:39:37 +0000 (15:39 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@1045 38d2e660-2303-0410-9eaa-f027e97ec537

kern/signal.c
kern/signal.h

index 8e0e6532482155f956259f485835a4ddee9b8c92..0e9770943b641819999ccd30352cdad2c873719e 100644 (file)
 
 #include "signal.h"
 
+#include <cfg/debug.h>
+#include <drv/timer.h>
 #include <kern/proc.h>
 #include <kern/proc_p.h>
-#include <cfg/debug.h>
 
 #if CONFIG_KERN_SIGNALS
 
 /**
  * Check if any of the signals in \a sigs has occurred and clear them.
- * Return the signals that have occurred.
+ * \return the signals that have occurred.
  */
 sigmask_t sig_check(sigmask_t sigs)
 {
@@ -165,7 +167,7 @@ sigmask_t sig_check(sigmask_t sigs)
 
 /**
  * Sleep until any of the signals in \a sigs occurs.
- * Return the signal(s) that have awaked the process.
+ * \return the signal(s) that have awaked the process.
  */
 sigmask_t sig_wait(sigmask_t sigs)
 {
@@ -193,6 +195,24 @@ sigmask_t sig_wait(sigmask_t sigs)
        return result;
 }
 
+/**
+ * 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 awaked the process.
+ * \note Caller must check return value to check which signal has awaked the process.
+ */
+sigmask_t sig_waitTimeout(sigmask_t sigs, ticks_t timeout)
+{
+       Timer t;
+
+       ASSERT(!sig_check(SIG_TIMEOUT));
+       ASSERT(!(sigs & SIG_TIMEOUT));
+       timer_set_event_signal(&t, proc_current(), SIG_TIMEOUT);
+       timer_setDelay(&t, timeout);
+       timer_add(&t);
+       return sig_wait(SIG_TIMEOUT | sigs);
+}
+
 
 /**
  * Send the signals \a sigs to the process \a proc.
index fed2e84c5144778b21b380c5958468e2683639d1..af3aed6b580ddf7bd31ce69cadf38f848ecfc6d0 100644 (file)
  * \author Bernardo Innocenti <bernie@develer.com>
  */
 
-/*#*
- *#* $Log$
- *#* Revision 1.8  2006/07/19 12:56:27  bernie
- *#* Convert to new Doxygen style.
- *#*
- *#* Revision 1.7  2005/11/04 16:20:02  bernie
- *#* Fix reference to README.devlib in header.
- *#*
- *#* Revision 1.6  2005/04/11 19:10:28  bernie
- *#* Include top-level headers from cfg/ subdir.
- *#*
- *#* Revision 1.5  2004/12/08 08:57:35  bernie
- *#* Rename sigset_t to sigmask_t.
- *#*
- *#* Revision 1.4  2004/08/25 14:12:09  rasky
- *#* Aggiornato il comment block dei log RCS
- *#*
- *#* Revision 1.3  2004/07/30 14:30:27  rasky
- *#* Resa la sig_signal interrupt safe (con il nuovo scheduler IRQ-safe)
- *#* Rimossa event_doIntr (ora inutile) e semplificata la logica delle macro con funzioni inline
- *#*
- *#* Revision 1.2  2004/06/03 11:27:09  bernie
- *#* Add dual-license information.
- *#*
- *#* Revision 1.1  2004/05/23 17:27:00  bernie
- *#* Import kern/ subdirectory.
- *#*/
 
 #ifndef KERN_SIGNAL_H
 #define KERN_SIGNAL_H
@@ -79,6 +52,7 @@ struct Process;
 sigmask_t sig_check(sigmask_t sigs);
 void sig_signal(struct Process *proc, sigmask_t sig);
 sigmask_t sig_wait(sigmask_t sigs);
+sigmask_t sig_waitTimeout(sigmask_t sigs, ticks_t timeout);
 
 
 /**
@@ -89,7 +63,7 @@ sigmask_t sig_wait(sigmask_t sigs);
 #define SIG_USER1    BV(1)  /**< Free for user usage */
 #define SIG_USER2    BV(2)  /**< Free for user usage */
 #define SIG_USER3    BV(3)  /**< Free for user usage */
-#define SIG_SYSTEM4  BV(4)  /**< Reserved for system use */
+#define SIG_TIMEOUT  BV(4)  /**< Reserved for timeout use */
 #define SIG_SYSTEM5  BV(5)  /**< Reserved for system use */
 #define SIG_SYSTEM6  BV(6)  /**< Reserved for system use */
 #define SIG_SINGLE   BV(7)  /**< Used to wait for a single event */