From 440be65010fb2c0e877047b7c3bf17b78588aefa Mon Sep 17 00:00:00 2001 From: Petro Karashchenko Date: Fri, 15 Sep 2023 21:57:03 +0300 Subject: [PATCH] spinlock: use spinlock API instead of direct asignment/compare Signed-off-by: Petro Karashchenko --- libs/libc/pthread/pthread_spinlock.c | 8 ++++---- mm/mempool/mempool.c | 2 +- sched/sched/sched_lock.c | 2 +- sched/sched/sched_unlock.c | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/libs/libc/pthread/pthread_spinlock.c b/libs/libc/pthread/pthread_spinlock.c index 75a3466bad..d5c1a78a40 100644 --- a/libs/libc/pthread/pthread_spinlock.c +++ b/libs/libc/pthread/pthread_spinlock.c @@ -92,7 +92,7 @@ int pthread_spin_init(FAR pthread_spinlock_t *lock, int pshared) DEBUGASSERT(lock != NULL); if (lock != NULL) { - lock->sp_lock = SP_UNLOCKED; + spin_initialize(&lock->sp_lock, SP_UNLOCKED); lock->sp_holder = IMPOSSIBLE_THREAD; ret = OK; } @@ -304,14 +304,14 @@ int pthread_spin_unlock(pthread_spinlock_t *lock) pthread_t me = pthread_self(); DEBUGASSERT(lock != NULL && - lock->sp_lock == SP_LOCKED && + spin_islocked(&lock->sp_lock) && lock->sp_holder == me); if (lock == NULL) { return EINVAL; } - else if (lock->sp_lock != SP_LOCKED || lock->sp_holder != me) + else if (!spin_islocked(&lock->sp_lock) || lock->sp_holder != me) { return EPERM; } @@ -319,7 +319,7 @@ int pthread_spin_unlock(pthread_spinlock_t *lock) /* Release the lock */ lock->sp_holder = IMPOSSIBLE_THREAD; - lock->sp_lock = SP_UNLOCKED; + spin_initialize(&lock->sp_lock, SP_UNLOCKED); return OK; } diff --git a/mm/mempool/mempool.c b/mm/mempool/mempool.c index 2f32814d00..4d36da1db9 100644 --- a/mm/mempool/mempool.c +++ b/mm/mempool/mempool.c @@ -186,7 +186,7 @@ int mempool_init(FAR struct mempool_s *pool, FAR const char *name) kasan_poison(base, size); } - spin_initialize(&pool->lock, 0); + spin_initialize(&pool->lock, SP_UNLOCKED); if (pool->wait && pool->expandsize == 0) { nxsem_init(&pool->waitsem, 0, 0); diff --git a/sched/sched/sched_lock.c b/sched/sched/sched_lock.c index 5d69771743..b839fbb7e4 100644 --- a/sched/sched/sched_lock.c +++ b/sched/sched/sched_lock.c @@ -181,7 +181,7 @@ int sched_lock(void) * and g_cpu_lockset should include the bit setting for this CPU. */ - DEBUGASSERT(g_cpu_schedlock == SP_LOCKED && + DEBUGASSERT(spin_islocked(&g_cpu_schedlock) && (g_cpu_lockset & (1 << this_cpu())) != 0); } diff --git a/sched/sched/sched_unlock.c b/sched/sched/sched_unlock.c index 6309e812fa..18b12f53f3 100644 --- a/sched/sched/sched_unlock.c +++ b/sched/sched/sched_unlock.c @@ -105,7 +105,7 @@ int sched_unlock(void) * release our hold on the lock. */ - DEBUGASSERT(g_cpu_schedlock == SP_LOCKED && + DEBUGASSERT(spin_islocked(&g_cpu_schedlock) && (g_cpu_lockset & (1 << cpu)) != 0); spin_clrbit(&g_cpu_lockset, cpu, &g_cpu_locksetlock,