Skip to content

Commit 5183fc5

Browse files
Mathieu Choplainnashif
authored andcommitted
kernel: assert no spinlock is held on swap when !USE_SWITCH
The do_swap() routine used when CONFIG_USE_SWITCH=y asserts that caller thread does not hold any spinlock when CONFIG_SPIN_VALIDATE is enabled. However, there is no similar check in place when CONFIG_USE_SWITCH=n. Copy this assertion in the USE_SWITCH=n implementation of z_swap_irqlock(). Signed-off-by: Mathieu Choplain <[email protected]>
1 parent 9c9dc0d commit 5183fc5

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

kernel/include/kswap.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,16 @@ static inline int z_swap_irqlock(unsigned int key)
203203
{
204204
int ret;
205205
z_check_stack_sentinel();
206+
207+
#ifdef CONFIG_SPIN_VALIDATE
208+
/* Refer to comment in do_swap() above for details */
209+
# ifndef CONFIG_ARM64
210+
__ASSERT(arch_irq_unlocked(key) ||
211+
_current->base.thread_state & (_THREAD_DUMMY | _THREAD_DEAD),
212+
"Context switching while holding lock!");
213+
# endif /* CONFIG_ARM64 */
214+
#endif /* CONFIG_SPIN_VALIDATE */
215+
206216
ret = arch_swap(key);
207217
return ret;
208218
}

0 commit comments

Comments
 (0)