kernel: move spinlock validation to own file

Move spin_lock validation outside of thread.c into own file. This code
really has nothing to do with the thread code.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
Anas Nashif 2024-02-22 21:56:37 -05:00
parent 7df7e834d9
commit a7d74f80ce
3 changed files with 45 additions and 39 deletions

View file

@ -84,6 +84,11 @@ endif()
endif()
if(CONFIG_SPIN_VALIDATE)
list(APPEND kernel_files
spinlock_validate.c)
endif()
if(CONFIG_XIP)
list(APPEND kernel_files
xip.c)

View file

@ -0,0 +1,40 @@
/*
* Copyright (c) 2018,2024 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/kernel.h>
#include <zephyr/spinlock.h>
bool z_spin_lock_valid(struct k_spinlock *l)
{
uintptr_t thread_cpu = l->thread_cpu;
if (thread_cpu != 0U) {
if ((thread_cpu & 3U) == _current_cpu->id) {
return false;
}
}
return true;
}
bool z_spin_unlock_valid(struct k_spinlock *l)
{
if (l->thread_cpu != (_current_cpu->id | (uintptr_t)_current)) {
return false;
}
l->thread_cpu = 0;
return true;
}
void z_spin_lock_set_owner(struct k_spinlock *l)
{
l->thread_cpu = _current_cpu->id | (uintptr_t)_current;
}
#ifdef CONFIG_KERNEL_COHERENCE
bool z_spin_lock_mem_coherent(struct k_spinlock *l)
{
return arch_mem_coherent((void *)l);
}
#endif /* CONFIG_KERNEL_COHERENCE */

View file

@ -945,45 +945,6 @@ FUNC_NORETURN void k_thread_user_mode_enter(k_thread_entry_t entry,
#endif
}
/* These spinlock assertion predicates are defined here because having
* them in spinlock.h is a giant header ordering headache.
*/
#ifdef CONFIG_SPIN_VALIDATE
bool z_spin_lock_valid(struct k_spinlock *l)
{
uintptr_t thread_cpu = l->thread_cpu;
if (thread_cpu != 0U) {
if ((thread_cpu & 3U) == _current_cpu->id) {
return false;
}
}
return true;
}
bool z_spin_unlock_valid(struct k_spinlock *l)
{
if (l->thread_cpu != (_current_cpu->id | (uintptr_t)_current)) {
return false;
}
l->thread_cpu = 0;
return true;
}
void z_spin_lock_set_owner(struct k_spinlock *l)
{
l->thread_cpu = _current_cpu->id | (uintptr_t)_current;
}
#ifdef CONFIG_KERNEL_COHERENCE
bool z_spin_lock_mem_coherent(struct k_spinlock *l)
{
return arch_mem_coherent((void *)l);
}
#endif /* CONFIG_KERNEL_COHERENCE */
#endif /* CONFIG_SPIN_VALIDATE */
int z_impl_k_float_disable(struct k_thread *thread)
{
#if defined(CONFIG_FPU) && defined(CONFIG_FPU_SHARING)