signal: speed up sig_check()
[bertos.git] / bertos / kern / signal.h
index 408e21e97538f2764b042fd7cb76fbccec8a5dd8..2c51f9e8aff07c8e562d6260909e4ee90c693c66 100644 (file)
 #include <cfg/compiler.h>
 #include <cfg/macros.h>    // BV()
 
-/* Fwd decl */
-struct Process;
+#include <cpu/irq.h>
+
+#include <kern/proc.h>
+
+#if CONFIG_KERN_SIGNALS
+
+INLINE sigmask_t __sig_checkSignal(Signal *s, sigmask_t sigs)
+{
+       sigmask_t result;
+
+       result = s->recv & sigs;
+       s->recv &= ~sigs;
+
+       return result;
+}
+
+/**
+ * Check if any of the signals in \a sigs has occurred and clear them.
+ *
+ * \return the signals that have occurred.
+ */
+INLINE sigmask_t sig_checkSignal(Signal *s, sigmask_t sigs)
+{
+       cpu_flags_t flags;
+       sigmask_t result;
+
+       IRQ_SAVE_DISABLE(flags);
+       result = __sig_checkSignal(s, sigs);
+       IRQ_RESTORE(flags);
+
+       return result;
+}
+
+INLINE sigmask_t sig_check(sigmask_t sigs)
+{
+       Process *proc = proc_current();
+       return sig_checkSignal(&proc->sig, sigs);
+}
+
+void sig_sendSignal(Signal *s, Process *proc, sigmask_t sig);
+
+INLINE void sig_send(Process *proc, sigmask_t sig)
+{
+       sig_sendSignal(&proc->sig, proc, sig);
+}
+
+void sig_postSignal(Signal *s, Process *proc, sigmask_t sig);
+
+INLINE void sig_post(Process *proc, sigmask_t sig)
+{
+       sig_postSignal(&proc->sig, proc, sig);
+}
 
-/* Inter-process Communication services */
-sigmask_t sig_check(sigmask_t sigs);
-void sig_send(struct Process *proc, sigmask_t sig);
-void sig_post(struct Process *proc, sigmask_t sig);
 /*
  * XXX: this is provided for backword compatibility, consider to make this
  * deprecated for the future.
  */
-INLINE void sig_signal(struct Process *proc, sigmask_t sig)
+INLINE void sig_signal(Process *proc, sigmask_t sig)
 {
-       sig_post(proc, sig);
+       sig_postSignal(&proc->sig, proc, sig);
 }
-sigmask_t sig_wait(sigmask_t sigs);
-sigmask_t sig_waitTimeout(sigmask_t sigs, ticks_t timeout);
+
+sigmask_t sig_waitSignal(Signal *s, sigmask_t sigs);
+
+INLINE sigmask_t sig_wait(sigmask_t sigs)
+{
+       Process *proc = proc_current();
+       return sig_waitSignal(&proc->sig, sigs);
+}
+
+sigmask_t sig_waitTimeoutSignal(Signal *s, sigmask_t sigs, ticks_t timeout);
+
+INLINE sigmask_t sig_waitTimeout(sigmask_t sigs, ticks_t timeout)
+{
+       Process *proc = proc_current();
+       return sig_waitTimeoutSignal(&proc->sig, sigs, timeout);
+}
+
+#endif /* CONFIG_KERN_SIGNALS */
 
 int signal_testRun(void);
 int signal_testSetup(void);
@@ -81,10 +143,15 @@ int signal_testTearDown(void);
 #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_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 */
+#define SIG_SINGLE   BV(4)  /**< Used to wait for a single event */
+#define SIG_SYSTEM5  BV(5)  /**< Reserved for internal system use */
+#define SIG_SYSTEM6  BV(6)  /**< Reserved for internal system use */
+#define SIG_TIMEOUT  BV(7)  /**< Reserved for timeout use */
+
+/**
+ * Max number of signals that can be used by drivers or user applications.
+ */
+#define SIG_USER_MAX SIG_SINGLE
 /*\}*/
 
 /* \} */ //defgroup kern_signal