diff options
author | Richard Braun <rbraun@sceen.net> | 2018-02-22 00:43:40 +0100 |
---|---|---|
committer | Richard Braun <rbraun@sceen.net> | 2018-02-22 00:43:40 +0100 |
commit | e8265363384bc3f8e6bb31466a3590ce27811efa (patch) | |
tree | b26cc2a341751deba5f801b6c16685a0d5f98fc0 /kern/spinlock_i.h | |
parent | 3dab066560158cde19ec8c7df3515a01bb04b746 (diff) |
kern/spinlock: add ownership tracking as a debugging feature
Diffstat (limited to 'kern/spinlock_i.h')
-rw-r--r-- | kern/spinlock_i.h | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/kern/spinlock_i.h b/kern/spinlock_i.h index c9dcdd10..a9f5fce5 100644 --- a/kern/spinlock_i.h +++ b/kern/spinlock_i.h @@ -26,6 +26,7 @@ #include <kern/error.h> #include <kern/macros.h> #include <kern/spinlock_types.h> +#include <kern/thread.h> #include <machine/cpu.h> /* @@ -36,6 +37,33 @@ #define SPINLOCK_UNLOCKED 0 #define SPINLOCK_LOCKED 1 +#ifdef CONFIG_SPINLOCK_DEBUG +#define SPINLOCK_TRACK_OWNER +#endif + +#ifdef SPINLOCK_TRACK_OWNER + +static inline void +spinlock_own(struct spinlock *lock) +{ + assert(!lock->owner); + lock->owner = thread_self(); +} + +static inline void +spinlock_disown(struct spinlock *lock) +{ + assert(lock->owner == thread_self()); + lock->owner = NULL; +} + +#else /* SPINLOCK_TRACK_OWNER */ + +#define spinlock_own(lock) +#define spinlock_disown(lock) + +#endif /* SPINLOCK_TRACK_OWNER */ + static inline int spinlock_lock_fast(struct spinlock *lock) { @@ -47,6 +75,7 @@ spinlock_lock_fast(struct spinlock *lock) return ERROR_BUSY; } + spinlock_own(lock); return 0; } @@ -55,6 +84,7 @@ spinlock_unlock_fast(struct spinlock *lock) { unsigned int prev; + spinlock_disown(lock); prev = atomic_cas_release(&lock->value, SPINLOCK_LOCKED, SPINLOCK_UNLOCKED); if (unlikely(prev != SPINLOCK_LOCKED)) { |