From 1241f910cedd42b4c899f981b349f375705e5f77 Mon Sep 17 00:00:00 2001 From: "chao.an" Date: Wed, 30 Dec 2020 14:24:51 +0800 Subject: [PATCH] arch/spinlock: implement the default test-and-set semantics use the default testset implement on single core platform that does not support test-and-set, more flexibility for SMP drivers(using spinlock) if configured in a single-core mode. Signed-off-by: chao.an --- include/nuttx/spinlock.h | 21 +++++++++++++++++++++ sched/Kconfig | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/include/nuttx/spinlock.h b/include/nuttx/spinlock.h index 676c9e7411..f560f75a91 100644 --- a/include/nuttx/spinlock.h +++ b/include/nuttx/spinlock.h @@ -128,7 +128,28 @@ * ****************************************************************************/ +#if defined(CONFIG_ARCH_HAVE_TESTSET) spinlock_t up_testset(volatile FAR spinlock_t *lock); +#elif !defined(CONFIG_SMP) +static inline spinlock_t up_testset(volatile FAR spinlock_t *lock) +{ + irqstate_t flags; + spinlock_t ret; + + flags = up_irq_save(); + + ret = *lock; + + if (ret == SP_UNLOCKED) + { + *lock = SP_LOCKED; + } + + up_irq_restore(flags); + + return ret; +} +#endif /**************************************************************************** * Name: spin_initialize diff --git a/sched/Kconfig b/sched/Kconfig index c246b54d22..777d1e1d2b 100644 --- a/sched/Kconfig +++ b/sched/Kconfig @@ -232,7 +232,6 @@ menu "Tasks and Scheduling" config SPINLOCK bool "Support Spinlocks" default n - depends on ARCH_HAVE_TESTSET ---help--- Enables support for spinlocks. Spinlocks are used primarily for synchronization in SMP configurations but are available for general @@ -275,6 +274,7 @@ config SMP bool "Symmetric Multi-Processing (SMP)" default n depends on ARCH_HAVE_MULTICPU + depends on ARCH_HAVE_TESTSET select SPINLOCK select SCHED_RESUMESCHEDULER select IRQCOUNT