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

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

commit f77887b891679f8e2186d48ee26cc315c06b7de6
Author: xuxingliang <[email protected]>
AuthorDate: Wed Aug 27 17:57:08 2025 +0800

    spinlock: add irq_save_nopreempt
    
    To disable interrupt and lock schedular
    
    Assisted-By: mimo-v2.6-pro
    Signed-off-by: xuxingliang <[email protected]>
---
 include/nuttx/spinlock.h | 45 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

diff --git a/include/nuttx/spinlock.h b/include/nuttx/spinlock.h
index bde3fef198d..4672b4a135e 100644
--- a/include/nuttx/spinlock.h
+++ b/include/nuttx/spinlock.h
@@ -33,6 +33,7 @@
 #include <assert.h>
 #include <stdint.h>
 #include <stdbool.h>
+#include <sched.h>
 
 #include <nuttx/compiler.h>
 #include <nuttx/irq.h>
@@ -1514,6 +1515,50 @@ void write_unlock_irqrestore(rwlock_t *lock, irqstate_t 
flags)
 
 #endif /* CONFIG_RW_SPINLOCK */
 
+/****************************************************************************
+ * Name: irq_save_nopreempt
+ *
+ * Description:
+ *     Disable local interrupts and disable preemption.
+ *
+ * Input Parameters:
+ *   lock - The spinlock to acquire
+ *
+ * Returned Value:
+ *   The previous IRQ state
+ *
+ ****************************************************************************/
+
+static inline_function
+irqstate_t irq_save_nopreempt(void)
+{
+  irqstate_t flags = up_irq_save();
+  sched_lock();
+
+  return flags;
+}
+
+/****************************************************************************
+ * Name: irq_restore_nopreempt
+ *
+ * Description:
+ *     Enable preemption and restore the interrupt state.
+ *
+ * Input Parameters:
+ *   flags  - flag of interrupts status
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+static inline_function
+void irq_restore_nopreempt(irqstate_t flags)
+{
+  sched_unlock();
+  up_irq_restore(flags);
+}
+
 #if defined(__cplusplus)
 }
 #endif

Reply via email to