You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by pk...@apache.org on 2023/10/30 09:18:42 UTC
(nuttx) 02/04: mm/gran: Replace the critical section with spin lock
This is an automated email from the ASF dual-hosted git repository.
pkarashchenko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit d5d4006c6b88f2c856d888a107f443832ecc77b1
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Sat Oct 21 17:20:02 2023 +0800
mm/gran: Replace the critical section with spin lock
Base on discusion: https://github.com/apache/nuttx/issues/10981
Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
mm/mm_gran/mm_gran.h | 2 ++
mm/mm_gran/mm_grancritical.c | 4 ++--
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/mm/mm_gran/mm_gran.h b/mm/mm_gran/mm_gran.h
index 3ef67916d3..5840d9682f 100644
--- a/mm/mm_gran/mm_gran.h
+++ b/mm/mm_gran/mm_gran.h
@@ -32,6 +32,7 @@
#include <arch/types.h>
#include <nuttx/mm/gran.h>
#include <nuttx/mutex.h>
+#include <nuttx/spinlock.h>
/****************************************************************************
* Pre-processor Definitions
@@ -68,6 +69,7 @@ struct gran_s
uint16_t ngranules; /* The total number of (aligned) granules in the heap */
#ifdef CONFIG_GRAN_INTR
irqstate_t irqstate; /* For exclusive access to the GAT */
+ spinlock_t lock;
#else
mutex_t lock; /* For exclusive access to the GAT */
#endif
diff --git a/mm/mm_gran/mm_grancritical.c b/mm/mm_gran/mm_grancritical.c
index 5a99a89a6d..0b988ecd07 100644
--- a/mm/mm_gran/mm_grancritical.c
+++ b/mm/mm_gran/mm_grancritical.c
@@ -57,7 +57,7 @@
int gran_enter_critical(FAR struct gran_s *priv)
{
#ifdef CONFIG_GRAN_INTR
- priv->irqstate = enter_critical_section();
+ priv->irqstate = spin_lock_irqsave(&priv->lock);
return OK;
#else
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)
{
#ifdef CONFIG_GRAN_INTR
- leave_critical_section(priv->irqstate);
+ spin_unlock_irqrestore(&priv->lock, priv->irqstate);
#else
nxmutex_unlock(&priv->lock);
#endif