Skip to content

Commit

Permalink
use small lock to protect g_ram_vectors, involving armv6-m, armv7-m, …
Browse files Browse the repository at this point in the history
…armv8-m.

Signed-off-by: wangzhi16 <wangzhi16@xiaomi.com>
  • Loading branch information
wangzhi-art authored and JerrySlhao committed Jan 10, 2025
1 parent 0694de1 commit 37cd0a1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
11 changes: 9 additions & 2 deletions arch/arm/src/armv6-m/arm_ramvec_attach.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,18 @@

#include <nuttx/irq.h>
#include <nuttx/arch.h>
#include <nuttx/spinlock.h>

#include "ram_vectors.h"

#ifdef CONFIG_ARCH_RAMVECTORS

/****************************************************************************
* Private Data
****************************************************************************/

static spinlock_t g_ramvec_lock = SP_UNLOCKED;

/****************************************************************************
* Public Functions
****************************************************************************/
Expand Down Expand Up @@ -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
Expand All @@ -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;
}

Expand Down
11 changes: 9 additions & 2 deletions arch/arm/src/armv7-m/arm_ramvec_attach.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,18 @@

#include <nuttx/irq.h>
#include <nuttx/arch.h>
#include <nuttx/spinlock.h>

#include "ram_vectors.h"

#ifdef CONFIG_ARCH_RAMVECTORS

/****************************************************************************
* Private Data
****************************************************************************/

static spinlock_t g_ramvec_lock = SP_UNLOCKED;

/****************************************************************************
* Public Functions
****************************************************************************/
Expand Down Expand Up @@ -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
Expand All @@ -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;
}

Expand Down
11 changes: 9 additions & 2 deletions arch/arm/src/armv8-m/arm_ramvec_attach.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,18 @@

#include <nuttx/irq.h>
#include <nuttx/arch.h>
#include <nuttx/spinlock.h>

#include "ram_vectors.h"

#ifdef CONFIG_ARCH_RAMVECTORS

/****************************************************************************
* Private Data
****************************************************************************/

static spinlock_t g_ramvec_lock = SP_UNLOCKED;

/****************************************************************************
* Public Functions
****************************************************************************/
Expand Down Expand Up @@ -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
Expand All @@ -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;
}

Expand Down

0 comments on commit 37cd0a1

Please sign in to comment.