Skip to content

Commit

Permalink
libc: Move the common implementation of up_testset to libc/machine
Browse files Browse the repository at this point in the history
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
  • Loading branch information
xiaoxiang781216 committed May 18, 2022
1 parent d93ffef commit 998bacf
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
21 changes: 0 additions & 21 deletions include/nuttx/spinlock.h
Expand Up @@ -107,28 +107,7 @@ typedef struct
*
****************************************************************************/

#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
Expand Down
23 changes: 23 additions & 0 deletions libs/libc/machine/arch_atomic.c
Expand Up @@ -733,3 +733,26 @@ SYNC_VAL_CMP_SWAP(4, uint32_t)
SYNC_VAL_CMP_SWAP(8, uint64_t)

#endif /* __clang__ */

/****************************************************************************
* Name: up_testset
****************************************************************************/

#if defined(CONFIG_SPINLOCK) && !defined(CONFIG_ARCH_HAVE_TESTSET)
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

0 comments on commit 998bacf

Please sign in to comment.