signal: speed up sig_check()
[bertos.git] / bertos / kern / signal.h
index a5d5e8d37e7495805e70277ec034f1bd7f5349d8..2c51f9e8aff07c8e562d6260909e4ee90c693c66 100644 (file)
 #include <cfg/compiler.h>
 #include <cfg/macros.h>    // BV()
 
+#include <cpu/irq.h>
+
 #include <kern/proc.h>
 
 #if CONFIG_KERN_SIGNALS
 
-/* Inter-process Communication services */
-sigmask_t sig_checkSignal(Signal *s, sigmask_t sigs);
+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)
 {