signal: introduce a struct to represent a signal
authorarighi <arighi@38d2e660-2303-0410-9eaa-f027e97ec537>
Thu, 3 Mar 2011 16:24:13 +0000 (16:24 +0000)
committerarighi <arighi@38d2e660-2303-0410-9eaa-f027e97ec537>
Thu, 3 Mar 2011 16:24:13 +0000 (16:24 +0000)
Replace the sig_recv and sig_wait mask with a single structure that
contains both masks.

This doesn't introduce any change in the code, it's just code restyling.

git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4748 38d2e660-2303-0410-9eaa-f027e97ec537

bertos/kern/proc.c
bertos/kern/proc.h
bertos/kern/signal.c
bertos/kern/signal.h

index 0bc046f803533999d3f52c46b3ff87b9e6803886..0bf820393beddf364973d508ce3cb8f77de3651e 100644 (file)
@@ -183,8 +183,8 @@ static void proc_initStruct(Process *proc)
        (void)proc;
 
 #if CONFIG_KERN_SIGNALS
-       proc->sig_recv = 0;
-       proc->sig_wait = 0;
+       proc->sig.recv = 0;
+       proc->sig.wait = 0;
 #endif
 
 #if CONFIG_KERN_HEAP
index 2849ca17588a989882dc3695598f273cc9ad2202..2def1459ef44362dac8da3699f70705ca5783c99 100644 (file)
 #include <cpu/types.h> // cpu_stack_t
 #include <cpu/frame.h> // CPU_SAVED_REGS_CNT
 
+#include <kern/signal.h>
+
 /*
  * WARNING: struct Process is considered private, so its definition can change any time
  * without notice. DO NOT RELY on any field defined here, use only the interface
@@ -122,8 +124,7 @@ typedef struct Process
        iptr_t       user_data;   /**< Custom data passed to the process */
 
 #if CONFIG_KERN_SIGNALS
-       sigmask_t    sig_wait;    /**< Signals the process is waiting for */
-       sigmask_t    sig_recv;    /**< Received signals */
+       Signal       sig;
 #endif
 
 #if CONFIG_KERN_HEAP
index 2f72c47906d6bf74899a55a03bedc63bd9912064..ef61a1e39ae73b65aa217d8542ff07a8c8098322 100644 (file)
@@ -152,8 +152,8 @@ sigmask_t sig_check(sigmask_t sigs)
        cpu_flags_t flags;
 
        IRQ_SAVE_DISABLE(flags);
-       result = current_process->sig_recv & sigs;
-       current_process->sig_recv &= ~sigs;
+       result = current_process->sig.recv & sigs;
+       current_process->sig.recv &= ~sigs;
        IRQ_RESTORE(flags);
 
        return result;
@@ -184,13 +184,13 @@ sigmask_t sig_wait(sigmask_t sigs)
        IRQ_DISABLE;
 
        /* Loop until we get at least one of the signals */
-       while (!(result = current_process->sig_recv & sigs))
+       while (!(result = current_process->sig.recv & sigs))
        {
                /*
                 * Tell "them" that we want to be awaken when any of these
                 * signals arrives.
                 */
-               current_process->sig_wait = sigs;
+               current_process->sig.wait = sigs;
 
                /* Go to sleep and proc_switch() to another process. */
                proc_switch();
@@ -200,12 +200,12 @@ sigmask_t sig_wait(sigmask_t sigs)
                 * least one of the signals we were expecting must have been
                 * delivered to us.
                 */
-               ASSERT(!current_process->sig_wait);
-               ASSERT(current_process->sig_recv & sigs);
+               ASSERT(!current_process->sig.wait);
+               ASSERT(current_process->sig.recv & sigs);
        }
 
        /* Signals found: clear them and return */
-       current_process->sig_recv &= ~sigs;
+       current_process->sig.recv &= ~sigs;
 
        IRQ_ENABLE;
        return result;
@@ -253,14 +253,14 @@ INLINE void __sig_signal(Process *proc, sigmask_t sigs, bool wakeup)
        IRQ_SAVE_DISABLE(flags);
 
        /* Set the signals */
-       proc->sig_recv |= sigs;
+       proc->sig.recv |= sigs;
 
        /* Check if process needs to be awoken */
-       if (proc->sig_recv & proc->sig_wait)
+       if (proc->sig.recv & proc->sig.wait)
        {
                ASSERT(proc != current_process);
 
-               proc->sig_wait = 0;
+               proc->sig.wait = 0;
                if (wakeup)
                        proc_wakeup(proc);
                else
index 408e21e97538f2764b042fd7cb76fbccec8a5dd8..30ce649ab8d3505dbe49978c20009ad01e18849b 100644 (file)
 /* Fwd decl */
 struct Process;
 
+/**
+ * Signal structure
+ */
+typedef struct Signal
+{
+       sigmask_t    wait;    /**< Signals the process is waiting for */
+       sigmask_t    recv;    /**< Received signals */
+} Signal;
+
 /* Inter-process Communication services */
 sigmask_t sig_check(sigmask_t sigs);
 void sig_send(struct Process *proc, sigmask_t sig);