Skip to content

Commit 1d51e88

Browse files
Andy Rossnashif
authored andcommitted
kernel/z_swap: Remove on-stack dummy spinlock
The z_swap_unlocked() function used a dummy spinlock for simplicity. But this runs afouls of checking for stack-resident spinlocks (forbidden when KERNEL_COHERENCE is set). And it's executing needless code to release the lock anyway. Replace with a compile time NULL, which will improve performance, correctness and code size. Signed-off-by: Andy Ross <[email protected]>
1 parent 38195d5 commit 1d51e88

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

kernel/include/kswap.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ static ALWAYS_INLINE unsigned int do_swap(unsigned int key,
6868

6969
z_check_stack_sentinel();
7070

71-
if (is_spinlock) {
71+
if (is_spinlock && lock != NULL) {
7272
k_spin_release(lock);
7373
}
7474

@@ -136,10 +136,7 @@ static inline int z_swap(struct k_spinlock *lock, k_spinlock_key_t key)
136136

137137
static inline void z_swap_unlocked(void)
138138
{
139-
struct k_spinlock lock = {};
140-
k_spinlock_key_t key = k_spin_lock(&lock);
141-
142-
(void) z_swap(&lock, key);
139+
(void) do_swap(arch_irq_lock(), NULL, 1);
143140
}
144141

145142
#else /* !CONFIG_USE_SWITCH */

0 commit comments

Comments
 (0)