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 <nuttx@fitbit.com>
This commit is contained in:
Sebastian Ene 2020-05-09 19:56:52 +03:00 committed by liuguo09
parent 08c4376606
commit 5db11a275e
4 changed files with 95 additions and 25 deletions

View File

@ -40,10 +40,6 @@
#ifndef __ARCH_SIM_INCLUDE_IRQ_H
#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

View File

@ -121,7 +121,7 @@ typedef unsigned int _size_t;
* up_irq_save()
*/
typedef unsigned int irqstate_t;
typedef _uint64_t irqstate_t;
#endif /* __ASSEMBLY__ */

View File

@ -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)

View File

@ -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)
{
}