4 * Copyright 2004 Develer S.r.l. (http://www.develer.com/)
5 * Copyright 1999,2000,2001 Bernardo Innocenti <bernie@develer.com>
6 * This file is part of DevLib - See devlib/README for information.
9 * \brief IPC signals implementation.
11 * Each process can wait for just one signal.
12 * Multiple processes can wait for the same signal. In this
13 * case, each signal will wake-up one of them.
17 * \author Bernardo Innocenti <bernie@develer.com>
22 * Revision 1.3 2004/07/30 14:24:16 rasky
23 * Task switching con salvataggio perfetto stato di interrupt (SR)
24 * Kernel monitor per dump informazioni su stack dei processi
26 * Revision 1.2 2004/06/03 11:27:09 bernie
27 * Add dual-license information.
29 * Revision 1.1 2004/05/23 17:27:00 bernie
30 * Import kern/ subdirectory.
40 #if CONFIG_KERN_SIGNALS
43 * Check if any of the signals in \a sigs has occurred and clear them.
44 * Return the signals that have occurred.
46 sigset_t sig_check(sigset_t sigs)
51 DISABLE_IRQSAVE(flags);
52 result = CurrentProcess->sig_recv & sigs;
53 CurrentProcess->sig_recv &= ~sigs;
54 ENABLE_IRQRESTORE(flags);
60 * Sleep until any of the signals in \a sigs occurs.
61 * Return the signal(s) that have awaked the process.
63 sigset_t sig_wait(sigset_t sigs)
68 DISABLE_IRQSAVE(flags);
70 /* Loop until we get at least one of the signals */
71 while (!(result = CurrentProcess->sig_recv & sigs))
73 /* go to sleep and proc_schedule() another process */
74 CurrentProcess->sig_wait = sigs;
78 /* Signals found: clear them and return */
79 CurrentProcess->sig_recv &= ~sigs;
80 ENABLE_IRQRESTORE(flags);
86 * Send the signals \a sigs to the process \a proc.
87 * The process will be awaken if it was waiting for any of them.
89 * This call is interrupt safe (no \c DISABLE_INTS/ENABLE_INTS protection)
91 void _sig_signal(Process *proc, sigset_t sigs)
94 proc->sig_recv |= sigs;
96 /* Check if process needs to be awaken */
97 if (proc->sig_recv & proc->sig_wait)
99 /* Wake up process and enqueue in ready list */
107 * Same as _sig_signal() with interrupt protection.
109 * \note Inlined manually because some compilers are too
110 * stupid to it automatically.
112 void sig_signal(Process *proc, sigset_t sigs)
116 /* Set the signals */
117 proc->sig_recv |= sigs;
119 /* Check if process needs to be awaken */
120 if (proc->sig_recv & proc->sig_wait)
122 /* Wake up process and enqueue in ready list */
130 #endif /* CONFIG_KERN_SIGNALS */