From 593c2a6e032d4696a67ddcc0dfb8401ef537fae4 Mon Sep 17 00:00:00 2001 From: arighi Date: Thu, 3 Mar 2011 16:24:13 +0000 Subject: [PATCH] signal: introduce a struct to represent a signal 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 | 4 ++-- bertos/kern/proc.h | 5 +++-- bertos/kern/signal.c | 20 ++++++++++---------- bertos/kern/signal.h | 9 +++++++++ 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/bertos/kern/proc.c b/bertos/kern/proc.c index 0bc046f8..0bf82039 100644 --- a/bertos/kern/proc.c +++ b/bertos/kern/proc.c @@ -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 diff --git a/bertos/kern/proc.h b/bertos/kern/proc.h index 2849ca17..2def1459 100644 --- a/bertos/kern/proc.h +++ b/bertos/kern/proc.h @@ -104,6 +104,8 @@ #include // cpu_stack_t #include // CPU_SAVED_REGS_CNT +#include + /* * 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 diff --git a/bertos/kern/signal.c b/bertos/kern/signal.c index 2f72c479..ef61a1e3 100644 --- a/bertos/kern/signal.c +++ b/bertos/kern/signal.c @@ -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 diff --git a/bertos/kern/signal.h b/bertos/kern/signal.h index 408e21e9..30ce649a 100644 --- a/bertos/kern/signal.h +++ b/bertos/kern/signal.h @@ -54,6 +54,15 @@ /* 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); -- 2.25.1