kernel/spinlock: Fix race in spinlock validation
The k_spin_lock() validation was setting the new owner of the spinlock BEFORE the actual lock was taken, so it could race against other processors trying the same thing. Split the modification step out into a separate function that can be called after we affirmatively have the lock. Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
This commit is contained in:
parent
5697dd7980
commit
f37e0c6e4d
2 changed files with 10 additions and 1 deletions
|
@ -38,6 +38,7 @@ static inline void z_arch_irq_unlock(int key)
|
|||
struct k_spinlock;
|
||||
int z_spin_lock_valid(struct k_spinlock *l);
|
||||
int z_spin_unlock_valid(struct k_spinlock *l);
|
||||
void z_spin_lock_set_owner(struct k_spinlock *l);
|
||||
#define SPIN_VALIDATE
|
||||
#endif
|
||||
#endif
|
||||
|
@ -81,6 +82,9 @@ static ALWAYS_INLINE k_spinlock_key_t k_spin_lock(struct k_spinlock *l)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifdef SPIN_VALIDATE
|
||||
z_spin_lock_set_owner(l);
|
||||
#endif
|
||||
return k;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue