kernel/spinlock: Fix SPIN_VALIDATE in ISRs
Spinlocks taken in ISRs were storing the _current thread pointer of the interrupted thread as the owner, which was never strictly correct but was benign as the thread would never run until the lock was released. But now k_thread_abort(_current) in an ISR has been fixed to eliminate all references to the (now aborted) thread struct, and _current points to a dummy thread. Handle that edge case in the validation framework. Signed-off-by: Andy Ross <andyross@google.com>
This commit is contained in:
parent
9b43fed10a
commit
93dc7e7438
1 changed files with 10 additions and 3 deletions
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#include <zephyr/kernel.h>
|
||||
#include <kernel_internal.h>
|
||||
#include <zephyr/spinlock.h>
|
||||
|
||||
bool z_spin_lock_valid(struct k_spinlock *l)
|
||||
|
@ -20,10 +20,17 @@ bool z_spin_lock_valid(struct k_spinlock *l)
|
|||
|
||||
bool z_spin_unlock_valid(struct k_spinlock *l)
|
||||
{
|
||||
if (l->thread_cpu != (_current_cpu->id | (uintptr_t)_current)) {
|
||||
uintptr_t tcpu = l->thread_cpu;
|
||||
|
||||
l->thread_cpu = 0;
|
||||
|
||||
if (arch_is_in_isr() && _current->base.thread_state & _THREAD_DUMMY) {
|
||||
/* Edge case where an ISR aborted _current */
|
||||
return true;
|
||||
}
|
||||
if (tcpu != (_current_cpu->id | (uintptr_t)_current)) {
|
||||
return false;
|
||||
}
|
||||
l->thread_cpu = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue