This is an automated email from the ASF dual-hosted git repository. liuhaitao pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit 5db11a275e5c82d2248673b6269013a2df81cd86 Author: Sebastian Ene <[email protected]> AuthorDate: Sat May 9 19:56:52 2020 +0300 arch/sim: Mask and restore the host signal in irq_save and irq_restore to avoid the host signal process interrupt the execution of NuttX critical section Signed-off-by: Sebastian Ene <[email protected]> --- arch/sim/include/irq.h | 26 ++----------- arch/sim/include/types.h | 2 +- arch/sim/src/Makefile | 4 +- arch/sim/src/sim/up_hostirq.c | 88 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 95 insertions(+), 25 deletions(-) diff --git a/arch/sim/include/irq.h b/arch/sim/include/irq.h index 6376039..808266b 100644 --- a/arch/sim/include/irq.h +++ b/arch/sim/include/irq.h @@ -41,10 +41,6 @@ #define __ARCH_SIM_INCLUDE_IRQ_H /**************************************************************************** - * Included Files - ****************************************************************************/ - -/**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -89,7 +85,7 @@ struct xcptcontext #endif /**************************************************************************** - * Inline functions + * Public Function Prototypes ****************************************************************************/ #ifndef __ASSEMBLY__ @@ -102,31 +98,17 @@ extern "C" #define EXTERN extern #endif -/**************************************************************************** - * Name: up_irqinitialize - ****************************************************************************/ - -static inline void up_irqinitialize(void) -{ -} - /* Name: up_irq_save, up_irq_restore, and friends. * - * NOTE: This function should never be called from application code and, + * NOTE: These functions should never be called from application code and, * as a general rule unless you really know what you are doing, this * function should not be called directly from operation system code either: * Typically, the wrapper functions, enter_critical_section() and * leave_critical section(), are probably what you really want. */ -static inline irqstate_t up_irq_save(void) -{ - return 0; -} - -static inline void up_irq_restore(irqstate_t flags) -{ -} +irqstate_t up_irq_save(void); +void up_irq_restore(irqstate_t flags); #undef EXTERN #ifdef __cplusplus diff --git a/arch/sim/include/types.h b/arch/sim/include/types.h index 7181a0b..d9d4fd3 100644 --- a/arch/sim/include/types.h +++ b/arch/sim/include/types.h @@ -121,7 +121,7 @@ typedef unsigned int _size_t; * up_irq_save() */ -typedef unsigned int irqstate_t; +typedef _uint64_t irqstate_t; #endif /* __ASSEMBLY__ */ diff --git a/arch/sim/src/Makefile b/arch/sim/src/Makefile index 79ce661..9df182d 100644 --- a/arch/sim/src/Makefile +++ b/arch/sim/src/Makefile @@ -83,7 +83,8 @@ ifeq ($(CONFIG_HOST_MACOS),y) HOSTCFLAGS += -Wno-deprecated-declarations endif -HOSTSRCS = up_hostmemory.c up_hosttime.c +HOSTSRCS = up_hostirq.c up_hostmemory.c up_hosttime.c +STDLIBS += -lpthread ifneq ($(CONFIG_HOST_MACOS),y) STDLIBS += -lrt endif @@ -108,7 +109,6 @@ ifeq ($(CONFIG_SCHED_INSTRUMENTATION),y) HOSTCFLAGS += -DCONFIG_SCHED_INSTRUMENTATION=1 endif HOSTSRCS += up_simsmp.c - STDLIBS += -lpthread endif ifeq ($(CONFIG_SCHED_INSTRUMENTATION),y) diff --git a/arch/sim/src/sim/up_hostirq.c b/arch/sim/src/sim/up_hostirq.c new file mode 100644 index 0000000..9acbd59 --- /dev/null +++ b/arch/sim/src/sim/up_hostirq.c @@ -0,0 +1,88 @@ +/**************************************************************************** + * arch/sim/src/sim/up_hostirq.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <signal.h> +#include <stddef.h> +#include <stdint.h> + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +union sigset_u +{ + uint64_t flags; + sigset_t sigset; +}; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: up_irq_save + * + * Description: + * Disable interrupts and returned the mask before disabling them. + * + ****************************************************************************/ + +uint64_t up_irq_save(void) +{ + union sigset_u nmask; + union sigset_u omask; + + sigfillset(&nmask.sigset); + pthread_sigmask(SIG_SETMASK, &nmask.sigset, &omask.sigset); + + return omask.flags; +} + +/**************************************************************************** + * Name: up_irq_restore + * + * Input Parameters: + * flags - the mask used to restore interrupts + * + * Description: + * Re-enable interrupts using the specified mask in flags argument. + * + ****************************************************************************/ + +void up_irq_restore(uint64_t flags) +{ + union sigset_u nmask; + + sigemptyset(&nmask.sigset); + nmask.flags = flags; + pthread_sigmask(SIG_SETMASK, &nmask.sigset, NULL); +} + +/**************************************************************************** + * Name: up_irqinitialize + ****************************************************************************/ + +void up_irqinitialize(void) +{ +}
