From b9837bed08d883456d4723f792aba64b90fa483c Mon Sep 17 00:00:00 2001 From: wangzhi16 Date: Tue, 7 Jan 2025 14:33:12 +0800 Subject: [PATCH] use small lock to protect g_ram_vectors, involving armv6-m, armv7-m, armv8-m. Signed-off-by: wangzhi16 --- arch/arm/src/armv6-m/arm_ramvec_attach.c | 11 +++++++++-- arch/arm/src/armv7-m/arm_ramvec_attach.c | 11 +++++++++-- arch/arm/src/armv8-m/arm_ramvec_attach.c | 11 +++++++++-- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/arch/arm/src/armv6-m/arm_ramvec_attach.c b/arch/arm/src/armv6-m/arm_ramvec_attach.c index 221f47dcbb..7f72a547f1 100644 --- a/arch/arm/src/armv6-m/arm_ramvec_attach.c +++ b/arch/arm/src/armv6-m/arm_ramvec_attach.c @@ -31,11 +31,18 @@ #include #include +#include #include "ram_vectors.h" #ifdef CONFIG_ARCH_RAMVECTORS +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static spinlock_t g_ramvec_lock = SP_UNLOCKED; + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -68,7 +75,7 @@ int arm_ramvec_attach(int irq, up_vector_t vector) * common exception handler. */ - flags = enter_critical_section(); + flags = spin_lock_irqsave(&g_ramvec_lock); if (vector == NULL) { /* Disable the interrupt if we can before detaching it. We might @@ -87,7 +94,7 @@ int arm_ramvec_attach(int irq, up_vector_t vector) /* Save the new vector in the vector table */ g_ram_vectors[irq] = vector; - leave_critical_section(flags); + spin_unlock_irqrestore(&g_ramvec_lock, flags); ret = OK; } diff --git a/arch/arm/src/armv7-m/arm_ramvec_attach.c b/arch/arm/src/armv7-m/arm_ramvec_attach.c index 16899e0629..ad331046bc 100644 --- a/arch/arm/src/armv7-m/arm_ramvec_attach.c +++ b/arch/arm/src/armv7-m/arm_ramvec_attach.c @@ -31,11 +31,18 @@ #include #include +#include #include "ram_vectors.h" #ifdef CONFIG_ARCH_RAMVECTORS +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static spinlock_t g_ramvec_lock = SP_UNLOCKED; + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -68,7 +75,7 @@ int arm_ramvec_attach(int irq, up_vector_t vector) * common exception handler. */ - flags = enter_critical_section(); + flags = spin_lock_irqsave(&g_ramvec_lock); if (vector == NULL) { /* Disable the interrupt if we can before detaching it. We might @@ -87,7 +94,7 @@ int arm_ramvec_attach(int irq, up_vector_t vector) /* Save the new vector in the vector table */ g_ram_vectors[irq] = vector; - leave_critical_section(flags); + spin_unlock_irqrestore(&g_ramvec_lock, flags); ret = OK; } diff --git a/arch/arm/src/armv8-m/arm_ramvec_attach.c b/arch/arm/src/armv8-m/arm_ramvec_attach.c index d882431db2..a08ea3af21 100644 --- a/arch/arm/src/armv8-m/arm_ramvec_attach.c +++ b/arch/arm/src/armv8-m/arm_ramvec_attach.c @@ -31,11 +31,18 @@ #include #include +#include #include "ram_vectors.h" #ifdef CONFIG_ARCH_RAMVECTORS +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static spinlock_t g_ramvec_lock = SP_UNLOCKED; + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -68,7 +75,7 @@ int arm_ramvec_attach(int irq, up_vector_t vector) * common exception handler. */ - flags = enter_critical_section(); + flags = spin_lock_irqsave(&g_ramvec_lock); if (vector == NULL) { /* Disable the interrupt if we can before detaching it. We might @@ -87,7 +94,7 @@ int arm_ramvec_attach(int irq, up_vector_t vector) /* Save the new vector in the vector table */ g_ram_vectors[irq] = vector; - leave_critical_section(flags); + spin_unlock_irqrestore(&g_ramvec_lock, flags); ret = OK; }