From 42acb44c35de3fd48eb1f20fc17eaf93b07f4b3d Mon Sep 17 00:00:00 2001 From: beveloper Date: Sun, 17 Nov 2002 00:28:32 +0000 Subject: [PATCH] added a couple of debugging checks into the spinlock functions git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1969 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kernel/core/smp.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/kernel/core/smp.c b/src/kernel/core/smp.c index 5de4d6d45e..d901424f21 100644 --- a/src/kernel/core/smp.c +++ b/src/kernel/core/smp.c @@ -24,6 +24,8 @@ #include +#define DEBUG_SPINLOCKS 1 + #define MSG_POOL_SIZE (SMP_MAX_CPUS * 4) struct smp_msg { @@ -74,6 +76,13 @@ acquire_spinlock(spinlock *lock) if (atomic_set((int32 *)lock, 1) == 0) break; } + } else { + #if DEBUG_SPINLOCKS + if (are_interrupts_enabled()) + panic("acquire_spinlock: attempt to acquire lock %p with interrupts enabled\n", lock); + if (atomic_set((int32 *)lock, 1) != 0) + panic("acquire_spinlock: attempt to acquire lock %p twice on non-SMP system\n", lock); + #endif } } @@ -82,12 +91,23 @@ static void acquire_spinlock_nocheck(spinlock *lock) { if (smp_num_cpus > 1) { + #if DEBUG_SPINLOCKS + if (are_interrupts_enabled()) + panic("acquire_spinlock_nocheck: attempt to acquire lock %p with interrupts enabled\n", lock); + #endif while (1) { while(*lock != 0) ; if (atomic_set((int32 *)lock, 1) == 0) break; } + } else { + #if DEBUG_SPINLOCKS + if (are_interrupts_enabled()) + panic("acquire_spinlock_nocheck: attempt to acquire lock %p with interrupts enabled\n", lock); + if (atomic_set((int32 *)lock, 1) != 0) + panic("acquire_spinlock_nocheck: attempt to acquire lock %p twice on non-SMP system\n", lock); + #endif } } @@ -95,7 +115,19 @@ acquire_spinlock_nocheck(spinlock *lock) void release_spinlock(spinlock *lock) { - *lock = 0; + if (smp_num_cpus > 1) { + if (are_interrupts_enabled()) + panic("release_spinlock: attempt to release lock %p with interrupts enabled\n", lock); + if (atomic_set((int32 *)lock, 0) != 1) + panic("release_spinlock: lock %p was already released\n", lock); + } else { + #if DEBUG_SPINLOCKS + if (are_interrupts_enabled()) + panic("release_spinlock: attempt to release lock %p with interrupts enabled\n", lock); + if (atomic_set((int32 *)lock, 0) != 1) + panic("release_spinlock: lock %p was already released\n", lock); + #endif + } }