spinlock: use spinlock API instead of direct asignment/compare

Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
This commit is contained in:
Petro Karashchenko 2023-09-15 21:57:03 +03:00 committed by Xiang Xiao
parent 057bfd3748
commit 440be65010
4 changed files with 7 additions and 7 deletions

View file

@ -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;
}

View file

@ -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);

View file

@ -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);
}

View file

@ -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,