This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 34e79f9618 spinlock: use spin_lock_init replace spin_initialize
34e79f9618 is described below

commit 34e79f961842be311f116f3ed5bad6ba2722e342
Author: hujun5 <huj...@xiaomi.com>
AuthorDate: Wed Nov 20 09:01:45 2024 +0800

    spinlock: use spin_lock_init replace spin_initialize
    
    reason:
    1: spin_lock_init and spin_initialize have similar functionalities.
    2: spin_lock and spin_unlock should be called in matching pairs.
    
    Signed-off-by: hujun5 <huj...@xiaomi.com>
---
 arch/risc-v/src/esp32c3/esp_coex_adapter.c     |  2 +-
 arch/risc-v/src/esp32c6/esp_coex_adapter.c     |  2 +-
 arch/xtensa/src/esp32/esp32_cpustart.c         |  7 ++++++-
 arch/xtensa/src/esp32/esp32_wifi_adapter.c     |  2 +-
 arch/xtensa/src/esp32s2/esp32s2_wifi_adapter.c |  2 +-
 arch/xtensa/src/esp32s3/esp32s3_cpustart.c     |  7 ++++++-
 arch/xtensa/src/esp32s3/esp32s3_wifi_adapter.c |  2 +-
 include/nuttx/spinlock.h                       | 20 --------------------
 libs/libc/pthread/pthread_spinlock.c           |  2 +-
 mm/mempool/mempool.c                           |  2 +-
 10 files changed, 19 insertions(+), 29 deletions(-)

diff --git a/arch/risc-v/src/esp32c3/esp_coex_adapter.c 
b/arch/risc-v/src/esp32c3/esp_coex_adapter.c
index 555363c72c..4d3eef0897 100644
--- a/arch/risc-v/src/esp32c3/esp_coex_adapter.c
+++ b/arch/risc-v/src/esp32c3/esp_coex_adapter.c
@@ -236,7 +236,7 @@ void *esp_coex_common_spin_lock_create_wrapper(void)
       DEBUGPANIC();
     }
 
-  spin_initialize(lock, SP_UNLOCKED);
+  spin_lock_init(lock);
 
   return lock;
 }
diff --git a/arch/risc-v/src/esp32c6/esp_coex_adapter.c 
b/arch/risc-v/src/esp32c6/esp_coex_adapter.c
index 0861115187..88fed2ea44 100644
--- a/arch/risc-v/src/esp32c6/esp_coex_adapter.c
+++ b/arch/risc-v/src/esp32c6/esp_coex_adapter.c
@@ -236,7 +236,7 @@ void *esp_coex_common_spin_lock_create_wrapper(void)
       DEBUGPANIC();
     }
 
-  spin_initialize(lock, SP_UNLOCKED);
+  spin_lock_init(lock);
 
   return lock;
 }
diff --git a/arch/xtensa/src/esp32/esp32_cpustart.c 
b/arch/xtensa/src/esp32/esp32_cpustart.c
index a83c7a5059..61bd4a3ca9 100644
--- a/arch/xtensa/src/esp32/esp32_cpustart.c
+++ b/arch/xtensa/src/esp32/esp32_cpustart.c
@@ -241,7 +241,8 @@ int up_cpu_start(int cpu)
        * try to lock it but spins until the APP CPU starts and unlocks it.
        */
 
-      spin_initialize(&g_appcpu_interlock, SP_LOCKED);
+      spin_lock_init(&g_appcpu_interlock);
+      spin_lock(&g_appcpu_interlock);
 
       /* Unstall the APP CPU */
 
@@ -288,6 +289,10 @@ int up_cpu_start(int cpu)
       /* And wait until the APP CPU starts and releases the spinlock. */
 
       spin_lock(&g_appcpu_interlock);
+
+      /* prev cpu boot done */
+
+      spin_unlock(&g_appcpu_interlock);
       DEBUGASSERT(g_appcpu_started);
     }
 
diff --git a/arch/xtensa/src/esp32/esp32_wifi_adapter.c 
b/arch/xtensa/src/esp32/esp32_wifi_adapter.c
index 3bd618f9c7..e7e2190a31 100644
--- a/arch/xtensa/src/esp32/esp32_wifi_adapter.c
+++ b/arch/xtensa/src/esp32/esp32_wifi_adapter.c
@@ -920,7 +920,7 @@ static void *esp_spin_lock_create(void)
       DEBUGPANIC();
     }
 
-  spin_initialize(lock, SP_UNLOCKED);
+  spin_lock_init(lock);
 
   return lock;
 }
diff --git a/arch/xtensa/src/esp32s2/esp32s2_wifi_adapter.c 
b/arch/xtensa/src/esp32s2/esp32s2_wifi_adapter.c
index 3d253e78c3..171a5ef079 100644
--- a/arch/xtensa/src/esp32s2/esp32s2_wifi_adapter.c
+++ b/arch/xtensa/src/esp32s2/esp32s2_wifi_adapter.c
@@ -879,7 +879,7 @@ static void *esp_spin_lock_create(void)
       DEBUGPANIC();
     }
 
-  spin_initialize(lock, SP_UNLOCKED);
+  spin_lock_init(lock);
 
   return lock;
 }
diff --git a/arch/xtensa/src/esp32s3/esp32s3_cpustart.c 
b/arch/xtensa/src/esp32s3/esp32s3_cpustart.c
index cec0cd3f58..1f933770fc 100644
--- a/arch/xtensa/src/esp32s3/esp32s3_cpustart.c
+++ b/arch/xtensa/src/esp32s3/esp32s3_cpustart.c
@@ -226,7 +226,8 @@ int up_cpu_start(int cpu)
        * try to lock it but spins until the APP CPU starts and unlocks it.
        */
 
-      spin_initialize(&g_appcpu_interlock, SP_LOCKED);
+      spin_lock_init(&g_appcpu_interlock);
+      spin_lock(&g_appcpu_interlock);
 
       /* OpenOCD might have already enabled clock gating and taken APP CPU
        * out of reset.  Don't reset the APP CPU if that's the case as this
@@ -272,6 +273,10 @@ int up_cpu_start(int cpu)
       /* And wait until the APP CPU starts and releases the spinlock. */
 
       spin_lock(&g_appcpu_interlock);
+
+      /* prev cpu boot done */
+
+      spin_unlock(&g_appcpu_interlock);
       DEBUGASSERT(g_appcpu_started);
     }
 
diff --git a/arch/xtensa/src/esp32s3/esp32s3_wifi_adapter.c 
b/arch/xtensa/src/esp32s3/esp32s3_wifi_adapter.c
index 4db4390e70..ce697ab4df 100644
--- a/arch/xtensa/src/esp32s3/esp32s3_wifi_adapter.c
+++ b/arch/xtensa/src/esp32s3/esp32s3_wifi_adapter.c
@@ -923,7 +923,7 @@ static void *esp_spin_lock_create(void)
       DEBUGPANIC();
     }
 
-  spin_initialize(lock, SP_UNLOCKED);
+  spin_lock_init(lock);
 
   return lock;
 }
diff --git a/include/nuttx/spinlock.h b/include/nuttx/spinlock.h
index bd15818d6a..c6a0cd43a8 100644
--- a/include/nuttx/spinlock.h
+++ b/include/nuttx/spinlock.h
@@ -495,26 +495,6 @@ static inline_function void spin_unlock(FAR volatile 
spinlock_t *lock)
 #  define spin_is_locked(l) (*(l) == SP_LOCKED)
 #endif
 
-/****************************************************************************
- * Name: spin_initialize
- *
- * Description:
- *   Initialize a non-reentrant spinlock object to its initial,
- *   unlocked state.
- *
- * Input Parameters:
- *   lock  - A reference to the spinlock object to be initialized.
- *   state - Initial state of the spinlock {SP_LOCKED or SP_UNLOCKED)
- *
- * Returned Value:
- *   None.
- *
- ****************************************************************************/
-
-/* void spin_initialize(FAR spinlock_t *lock, spinlock_t state); */
-
-#define spin_initialize(l,s) do { SP_DMB(); *(l) = (s); } while (0)
-
 /****************************************************************************
  * Name: spin_lock_irqsave_wo_note
  *
diff --git a/libs/libc/pthread/pthread_spinlock.c 
b/libs/libc/pthread/pthread_spinlock.c
index 4bd9847f31..2af32e5a74 100644
--- a/libs/libc/pthread/pthread_spinlock.c
+++ b/libs/libc/pthread/pthread_spinlock.c
@@ -94,7 +94,7 @@ int pthread_spin_init(FAR pthread_spinlock_t *lock, int 
pshared)
   DEBUGASSERT(lock != NULL);
   if (lock != NULL)
     {
-      spin_initialize(&lock->sp_lock, SP_UNLOCKED);
+      spin_lock_init(&lock->sp_lock);
       lock->sp_holder = IMPOSSIBLE_THREAD;
       ret             = OK;
     }
diff --git a/mm/mempool/mempool.c b/mm/mempool/mempool.c
index ed8dd6a9e6..624ce291cb 100644
--- a/mm/mempool/mempool.c
+++ b/mm/mempool/mempool.c
@@ -304,7 +304,7 @@ int mempool_init(FAR struct mempool_s *pool, FAR const char 
*name)
       kasan_poison(base, size);
     }
 
-  spin_initialize(&pool->lock, SP_UNLOCKED);
+  spin_lock_init(&pool->lock);
   if (pool->wait && pool->expandsize == 0)
     {
       nxsem_init(&pool->waitsem, 0, 0);

Reply via email to