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.4 2004/07/30 14:30:27 rasky
23 * Resa la sig_signal interrupt safe (con il nuovo scheduler IRQ-safe)
24 * Rimossa event_doIntr (ora inutile) e semplificata la logica delle macro con funzioni inline
26 * Revision 1.3 2004/07/30 14:24:16 rasky
27 * Task switching con salvataggio perfetto stato di interrupt (SR)
28 * Kernel monitor per dump informazioni su stack dei processi
30 * Revision 1.2 2004/06/03 11:27:09 bernie
31 * Add dual-license information.
33 * Revision 1.1 2004/05/23 17:27:00 bernie
34 * Import kern/ subdirectory.
44 #if CONFIG_KERN_SIGNALS
47 * Check if any of the signals in \a sigs has occurred and clear them.
48 * Return the signals that have occurred.
50 sigset_t sig_check(sigset_t sigs)
55 DISABLE_IRQSAVE(flags);
56 result = CurrentProcess->sig_recv & sigs;
57 CurrentProcess->sig_recv &= ~sigs;
58 ENABLE_IRQRESTORE(flags);
64 * Sleep until any of the signals in \a sigs occurs.
65 * Return the signal(s) that have awaked the process.
67 sigset_t sig_wait(sigset_t sigs)
72 DISABLE_IRQSAVE(flags);
74 /* Loop until we get at least one of the signals */
75 while (!(result = CurrentProcess->sig_recv & sigs))
77 /* go to sleep and proc_schedule() another process */
78 CurrentProcess->sig_wait = sigs;
82 /* Signals found: clear them and return */
83 CurrentProcess->sig_recv &= ~sigs;
84 ENABLE_IRQRESTORE(flags);
90 * Send the signals \a sigs to the process \a proc.
91 * The process will be awaken if it was waiting for any of them.
93 * \note This call is interrupt safe.
95 void sig_signal(Process *proc, sigset_t sigs)
98 DISABLE_IRQSAVE(flags);
100 /* Set the signals */
101 proc->sig_recv |= sigs;
103 /* Check if process needs to be awaken */
104 if (proc->sig_recv & proc->sig_wait)
106 /* Wake up process and enqueue in ready list */
111 ENABLE_IRQRESTORE(flags);
114 #endif /* CONFIG_KERN_SIGNALS */