Consistently use KDEBUG. It is always defined and therefore must be

checked with "#if".


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28247 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2008-10-20 13:06:04 +00:00
parent b2568a30b1
commit 1894a0a98b
6 changed files with 38 additions and 33 deletions
+10 -5
View File
@@ -14,12 +14,17 @@
#include <module.h> #include <module.h>
#if DEBUG /* KDEBUG
/* The kernel debug level.
* The kernel debug level. Level 1 is usual asserts, > 1 should be used for very expensive runtime
* Level 1 is usual asserts, > 1 should be used for very expensive runtime checks checks
*/ */
# define KDEBUG 1 #if !defined(KDEBUG)
# if DEBUG
# define KDEBUG 1
# else
# define KDEBUG 0
# endif
#endif #endif
#define ASSERT_ALWAYS(x) \ #define ASSERT_ALWAYS(x) \
+8 -8
View File
@@ -18,7 +18,7 @@ struct mutex_waiter;
typedef struct mutex { typedef struct mutex {
const char* name; const char* name;
struct mutex_waiter* waiters; struct mutex_waiter* waiters;
#ifdef KDEBUG #if KDEBUG
thread_id holder; thread_id holder;
#else #else
int32 count; int32 count;
@@ -31,7 +31,7 @@ typedef struct mutex {
typedef struct recursive_lock { typedef struct recursive_lock {
mutex lock; mutex lock;
#ifndef KDEBUG #if !KDEBUG
thread_id holder; thread_id holder;
#endif #endif
int recursion; int recursion;
@@ -77,7 +77,7 @@ typedef struct rw_lock {
// static initializers // static initializers
#ifdef KDEBUG #if KDEBUG
# define MUTEX_INITIALIZER(name) { name, NULL, -1, 0 } # define MUTEX_INITIALIZER(name) { name, NULL, -1, 0 }
# define RECURSIVE_LOCK_INITIALIZER(name) { MUTEX_INITIALIZER(name), 0 } # define RECURSIVE_LOCK_INITIALIZER(name) { MUTEX_INITIALIZER(name), 0 }
#else #else
@@ -130,7 +130,7 @@ extern status_t _mutex_trylock(mutex* lock);
static inline status_t static inline status_t
mutex_lock(mutex* lock) mutex_lock(mutex* lock)
{ {
#ifdef KDEBUG #if KDEBUG
return _mutex_lock(lock, false); return _mutex_lock(lock, false);
#else #else
if (atomic_add(&lock->count, -1) < 0) if (atomic_add(&lock->count, -1) < 0)
@@ -143,7 +143,7 @@ mutex_lock(mutex* lock)
static inline status_t static inline status_t
mutex_lock_threads_locked(mutex* lock) mutex_lock_threads_locked(mutex* lock)
{ {
#ifdef KDEBUG #if KDEBUG
return _mutex_lock(lock, true); return _mutex_lock(lock, true);
#else #else
if (atomic_add(&lock->count, -1) < 0) if (atomic_add(&lock->count, -1) < 0)
@@ -156,7 +156,7 @@ mutex_lock_threads_locked(mutex* lock)
static inline status_t static inline status_t
mutex_trylock(mutex* lock) mutex_trylock(mutex* lock)
{ {
#ifdef KDEBUG #if KDEBUG
return _mutex_trylock(lock); return _mutex_trylock(lock);
#else #else
if (atomic_test_and_set(&lock->count, -1, 0) != 0) if (atomic_test_and_set(&lock->count, -1, 0) != 0)
@@ -169,7 +169,7 @@ mutex_trylock(mutex* lock)
static inline void static inline void
mutex_unlock(mutex* lock) mutex_unlock(mutex* lock)
{ {
#if !defined(KDEBUG) #if !KDEBUG
if (atomic_add(&lock->count, 1) < -1) if (atomic_add(&lock->count, 1) < -1)
#endif #endif
_mutex_unlock(lock, false); _mutex_unlock(lock, false);
@@ -179,7 +179,7 @@ mutex_unlock(mutex* lock)
static inline void static inline void
mutex_transfer_lock(mutex* lock, thread_id thread) mutex_transfer_lock(mutex* lock, thread_id thread)
{ {
#ifdef KDEBUG #if KDEBUG
lock->holder = thread; lock->holder = thread;
#endif #endif
} }
@@ -2239,7 +2239,7 @@ TCPEndpoint::Dump() const
kprintf("TCP endpoint %p\n", this); kprintf("TCP endpoint %p\n", this);
kprintf(" state: %s\n", name_for_state(fState)); kprintf(" state: %s\n", name_for_state(fState));
kprintf(" flags: 0x%lx\n", fFlags); kprintf(" flags: 0x%lx\n", fFlags);
#ifdef KDEBUG #if KDEBUG
kprintf(" lock: { %p, holder: %ld }\n", &fLock, fLock.holder); kprintf(" lock: { %p, holder: %ld }\n", &fLock, fLock.holder);
#endif #endif
kprintf(" accept sem: %ld\n", fAcceptSemaphore); kprintf(" accept sem: %ld\n", fAcceptSemaphore);
+1 -1
View File
@@ -71,7 +71,7 @@
#define HAS_FS_CALL(vnode, op) (vnode->ops->op != NULL) #define HAS_FS_CALL(vnode, op) (vnode->ops->op != NULL)
#define HAS_FS_MOUNT_CALL(mount, op) (mount->volume->ops->op != NULL) #define HAS_FS_MOUNT_CALL(mount, op) (mount->volume->ops->op != NULL)
#ifdef KDEBUG #if KDEBUG
# define FS_CALL(vnode, op, params...) \ # define FS_CALL(vnode, op, params...) \
( HAS_FS_CALL(vnode, op) ? \ ( HAS_FS_CALL(vnode, op) ? \
vnode->ops->op(vnode->mount->volume, vnode, params) \ vnode->ops->op(vnode->mount->volume, vnode, params) \
+17 -17
View File
@@ -43,7 +43,7 @@ struct rw_lock_waiter {
#define RW_LOCK_FLAG_OWNS_NAME RW_LOCK_FLAG_CLONE_NAME #define RW_LOCK_FLAG_OWNS_NAME RW_LOCK_FLAG_CLONE_NAME
#ifdef KDEBUG #if KDEBUG
# define RECURSIVE_LOCK_HOLDER(lock) ((lock)->lock.holder) # define RECURSIVE_LOCK_HOLDER(lock) ((lock)->lock.holder)
#else #else
# define RECURSIVE_LOCK_HOLDER(lock) ((lock)->holder) # define RECURSIVE_LOCK_HOLDER(lock) ((lock)->holder)
@@ -100,7 +100,7 @@ recursive_lock_lock(recursive_lock *lock)
if (thread != RECURSIVE_LOCK_HOLDER(lock)) { if (thread != RECURSIVE_LOCK_HOLDER(lock)) {
mutex_lock(&lock->lock); mutex_lock(&lock->lock);
#ifndef KDEBUG #if !KDEBUG
lock->holder = thread; lock->holder = thread;
#endif #endif
} }
@@ -124,7 +124,7 @@ recursive_lock_trylock(recursive_lock *lock)
if (status != B_OK) if (status != B_OK)
return status; return status;
#ifndef KDEBUG #if !KDEBUG
lock->holder = thread; lock->holder = thread;
#endif #endif
} }
@@ -141,7 +141,7 @@ recursive_lock_unlock(recursive_lock *lock)
panic("recursive_lock %p unlocked by non-holder thread!\n", lock); panic("recursive_lock %p unlocked by non-holder thread!\n", lock);
if (--lock->recursion == 0) { if (--lock->recursion == 0) {
#ifndef KDEBUG #if !KDEBUG
lock->holder = -1; lock->holder = -1;
#endif #endif
mutex_unlock(&lock->lock); mutex_unlock(&lock->lock);
@@ -253,7 +253,7 @@ rw_lock_destroy(rw_lock* lock)
// unblock all waiters // unblock all waiters
InterruptsSpinLocker locker(gThreadSpinlock); InterruptsSpinLocker locker(gThreadSpinlock);
#ifdef KDEBUG #if KDEBUG
if (lock->waiters != NULL && thread_get_current_thread_id() if (lock->waiters != NULL && thread_get_current_thread_id()
!= lock->holder) { != lock->holder) {
panic("rw_lock_destroy(): there are blocking threads, but the caller " panic("rw_lock_destroy(): there are blocking threads, but the caller "
@@ -429,7 +429,7 @@ mutex_init(mutex* lock, const char *name)
{ {
lock->name = name; lock->name = name;
lock->waiters = NULL; lock->waiters = NULL;
#ifdef KDEBUG #if KDEBUG
lock->holder = -1; lock->holder = -1;
#else #else
lock->count = 0; lock->count = 0;
@@ -445,7 +445,7 @@ mutex_init_etc(mutex* lock, const char *name, uint32 flags)
{ {
lock->name = (flags & MUTEX_FLAG_CLONE_NAME) != 0 ? strdup(name) : name; lock->name = (flags & MUTEX_FLAG_CLONE_NAME) != 0 ? strdup(name) : name;
lock->waiters = NULL; lock->waiters = NULL;
#ifdef KDEBUG #if KDEBUG
lock->holder = -1; lock->holder = -1;
#else #else
lock->count = 0; lock->count = 0;
@@ -465,7 +465,7 @@ mutex_destroy(mutex* lock)
// unblock all waiters // unblock all waiters
InterruptsSpinLocker locker(gThreadSpinlock); InterruptsSpinLocker locker(gThreadSpinlock);
#ifdef KDEBUG #if KDEBUG
if (lock->waiters != NULL && thread_get_current_thread_id() if (lock->waiters != NULL && thread_get_current_thread_id()
!= lock->holder) { != lock->holder) {
panic("mutex_destroy(): there are blocking threads, but caller doesn't " panic("mutex_destroy(): there are blocking threads, but caller doesn't "
@@ -496,7 +496,7 @@ mutex_switch_lock(mutex* from, mutex* to)
{ {
InterruptsSpinLocker locker(gThreadSpinlock); InterruptsSpinLocker locker(gThreadSpinlock);
#if !defined(KDEBUG) #if !KDEBUG
if (atomic_add(&from->count, 1) < -1) if (atomic_add(&from->count, 1) < -1)
#endif #endif
_mutex_unlock(from, true); _mutex_unlock(from, true);
@@ -508,7 +508,7 @@ mutex_switch_lock(mutex* from, mutex* to)
status_t status_t
_mutex_lock(mutex* lock, bool threadsLocked) _mutex_lock(mutex* lock, bool threadsLocked)
{ {
#ifdef KDEBUG #if KDEBUG
if (!gKernelStartup && !threadsLocked && !are_interrupts_enabled()) { if (!gKernelStartup && !threadsLocked && !are_interrupts_enabled()) {
panic("_mutex_lock(): called with interrupts disabled for lock %p", panic("_mutex_lock(): called with interrupts disabled for lock %p",
lock); lock);
@@ -520,7 +520,7 @@ _mutex_lock(mutex* lock, bool threadsLocked)
// Might have been released after we decremented the count, but before // Might have been released after we decremented the count, but before
// we acquired the spinlock. // we acquired the spinlock.
#ifdef KDEBUG #if KDEBUG
if (lock->holder < 0) { if (lock->holder < 0) {
lock->holder = thread_get_current_thread_id(); lock->holder = thread_get_current_thread_id();
return B_OK; return B_OK;
@@ -552,7 +552,7 @@ _mutex_lock(mutex* lock, bool threadsLocked)
thread_prepare_to_block(waiter.thread, 0, THREAD_BLOCK_TYPE_MUTEX, lock); thread_prepare_to_block(waiter.thread, 0, THREAD_BLOCK_TYPE_MUTEX, lock);
status_t error = thread_block_locked(waiter.thread); status_t error = thread_block_locked(waiter.thread);
#ifdef KDEBUG #if KDEBUG
if (error == B_OK) if (error == B_OK)
lock->holder = waiter.thread->id; lock->holder = waiter.thread->id;
#endif #endif
@@ -567,7 +567,7 @@ _mutex_unlock(mutex* lock, bool threadsLocked)
// lock only, if !threadsLocked // lock only, if !threadsLocked
InterruptsSpinLocker locker(gThreadSpinlock, false, !threadsLocked); InterruptsSpinLocker locker(gThreadSpinlock, false, !threadsLocked);
#ifdef KDEBUG #if KDEBUG
if (thread_get_current_thread_id() != lock->holder) { if (thread_get_current_thread_id() != lock->holder) {
panic("_mutex_unlock() failure: thread %ld is trying to release " panic("_mutex_unlock() failure: thread %ld is trying to release "
"mutex %p (current holder %ld)\n", thread_get_current_thread_id(), "mutex %p (current holder %ld)\n", thread_get_current_thread_id(),
@@ -586,7 +586,7 @@ _mutex_unlock(mutex* lock, bool threadsLocked)
// unblock thread // unblock thread
thread_unblock_locked(waiter->thread, B_OK); thread_unblock_locked(waiter->thread, B_OK);
#ifdef KDEBUG #if KDEBUG
// Already set the holder to the unblocked thread. Besides that this // Already set the holder to the unblocked thread. Besides that this
// actually reflects the current situation, setting it to -1 would // actually reflects the current situation, setting it to -1 would
// cause a race condition, since another locker could think the lock // cause a race condition, since another locker could think the lock
@@ -596,7 +596,7 @@ _mutex_unlock(mutex* lock, bool threadsLocked)
} else { } else {
// We've acquired the spinlock before the locker that is going to wait. // We've acquired the spinlock before the locker that is going to wait.
// Just mark the lock as released. // Just mark the lock as released.
#ifdef KDEBUG #if KDEBUG
lock->holder = -1; lock->holder = -1;
#else #else
lock->flags |= MUTEX_FLAG_RELEASED; lock->flags |= MUTEX_FLAG_RELEASED;
@@ -608,7 +608,7 @@ _mutex_unlock(mutex* lock, bool threadsLocked)
status_t status_t
_mutex_trylock(mutex* lock) _mutex_trylock(mutex* lock)
{ {
#ifdef KDEBUG #if KDEBUG
InterruptsSpinLocker _(gThreadSpinlock); InterruptsSpinLocker _(gThreadSpinlock);
if (lock->holder <= 0) { if (lock->holder <= 0) {
@@ -638,7 +638,7 @@ dump_mutex_info(int argc, char** argv)
kprintf("mutex %p:\n", lock); kprintf("mutex %p:\n", lock);
kprintf(" name: %s\n", lock->name); kprintf(" name: %s\n", lock->name);
kprintf(" flags: 0x%x\n", lock->flags); kprintf(" flags: 0x%x\n", lock->flags);
#ifdef KDEBUG #if KDEBUG
kprintf(" holder: %ld\n", lock->holder); kprintf(" holder: %ld\n", lock->holder);
#else #else
kprintf(" count: %ld\n", lock->count); kprintf(" count: %ld\n", lock->count);
+1 -1
View File
@@ -3465,7 +3465,7 @@ dump_cache(int argc, char **argv)
kprintf(" temporary: %ld\n", cache->temporary); kprintf(" temporary: %ld\n", cache->temporary);
kprintf(" scan_skip: %ld\n", cache->scan_skip); kprintf(" scan_skip: %ld\n", cache->scan_skip);
kprintf(" lock: %p\n", cache->GetLock()); kprintf(" lock: %p\n", cache->GetLock());
#ifdef KDEBUG #if KDEBUG
kprintf(" lock.holder: %ld\n", cache->GetLock()->holder); kprintf(" lock.holder: %ld\n", cache->GetLock()->holder);
#endif #endif
kprintf(" areas:\n"); kprintf(" areas:\n");