mm/gran: Replace the critical section with spin lock
Base on discusion: https://github.com/apache/nuttx/issues/10981 Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
parent
08bae13624
commit
d5d4006c6b
|
@ -32,6 +32,7 @@
|
||||||
#include <arch/types.h>
|
#include <arch/types.h>
|
||||||
#include <nuttx/mm/gran.h>
|
#include <nuttx/mm/gran.h>
|
||||||
#include <nuttx/mutex.h>
|
#include <nuttx/mutex.h>
|
||||||
|
#include <nuttx/spinlock.h>
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Pre-processor Definitions
|
* Pre-processor Definitions
|
||||||
|
@ -68,6 +69,7 @@ struct gran_s
|
||||||
uint16_t ngranules; /* The total number of (aligned) granules in the heap */
|
uint16_t ngranules; /* The total number of (aligned) granules in the heap */
|
||||||
#ifdef CONFIG_GRAN_INTR
|
#ifdef CONFIG_GRAN_INTR
|
||||||
irqstate_t irqstate; /* For exclusive access to the GAT */
|
irqstate_t irqstate; /* For exclusive access to the GAT */
|
||||||
|
spinlock_t lock;
|
||||||
#else
|
#else
|
||||||
mutex_t lock; /* For exclusive access to the GAT */
|
mutex_t lock; /* For exclusive access to the GAT */
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -57,7 +57,7 @@
|
||||||
int gran_enter_critical(FAR struct gran_s *priv)
|
int gran_enter_critical(FAR struct gran_s *priv)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_GRAN_INTR
|
#ifdef CONFIG_GRAN_INTR
|
||||||
priv->irqstate = enter_critical_section();
|
priv->irqstate = spin_lock_irqsave(&priv->lock);
|
||||||
return OK;
|
return OK;
|
||||||
#else
|
#else
|
||||||
return nxmutex_lock(&priv->lock);
|
return nxmutex_lock(&priv->lock);
|
||||||
|
@ -67,7 +67,7 @@ int gran_enter_critical(FAR struct gran_s *priv)
|
||||||
void gran_leave_critical(FAR struct gran_s *priv)
|
void gran_leave_critical(FAR struct gran_s *priv)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_GRAN_INTR
|
#ifdef CONFIG_GRAN_INTR
|
||||||
leave_critical_section(priv->irqstate);
|
spin_unlock_irqrestore(&priv->lock, priv->irqstate);
|
||||||
#else
|
#else
|
||||||
nxmutex_unlock(&priv->lock);
|
nxmutex_unlock(&priv->lock);
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue