#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)
{
/**
* 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)
{
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.
* \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
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);
/**
#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 */