Re-apply:

Invert the sense of the bit to mark if LOCKDEBUG is enabled to
	disabled.

	This will help my fellow developers spot "use before initialised"
	problems that hppa picks up very well.

but fix the !LOCKDEBUG case by defining the "no debug" bits to zero so
they have no effect on lock stubs.
This commit is contained in:
skrll 2010-02-08 09:54:27 +00:00
parent 0961cec7ef
commit c53ddcfff2
4 changed files with 32 additions and 23 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: kern_mutex.c,v 1.48 2010/02/06 04:50:19 cube Exp $ */
/* $NetBSD: kern_mutex.c,v 1.49 2010/02/08 09:54:27 skrll Exp $ */
/*-
* Copyright (c) 2002, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@ -40,7 +40,7 @@
#define __MUTEX_PRIVATE
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: kern_mutex.c,v 1.48 2010/02/06 04:50:19 cube Exp $");
__KERNEL_RCSID(0, "$NetBSD: kern_mutex.c,v 1.49 2010/02/08 09:54:27 skrll Exp $");
#include <sys/param.h>
#include <sys/atomic.h>
@ -156,16 +156,16 @@ do { \
(((int)(mtx)->mtx_owner & MUTEX_BIT_WAITERS) != 0)
#define MUTEX_INITIALIZE_ADAPTIVE(mtx, dodebug) \
if (!dodebug) \
(mtx)->mtx_owner |= MUTEX_BIT_NODEBUG; \
do { \
if (dodebug) \
(mtx)->mtx_owner |= MUTEX_BIT_DEBUG; \
} while (/* CONSTCOND */ 0);
#define MUTEX_INITIALIZE_SPIN(mtx, dodebug, ipl) \
do { \
(mtx)->mtx_owner = MUTEX_BIT_SPIN; \
if (dodebug) \
(mtx)->mtx_owner |= MUTEX_BIT_DEBUG; \
if (!dodebug) \
(mtx)->mtx_owner |= MUTEX_BIT_NODEBUG; \
(mtx)->mtx_ipl = makeiplcookie((ipl)); \
__cpu_simple_lock_init(&(mtx)->mtx_lock); \
} while (/* CONSTCOND */ 0)
@ -180,10 +180,10 @@ do { \
#define MUTEX_ADAPTIVE_P(mtx) \
(((mtx)->mtx_owner & MUTEX_BIT_SPIN) == 0)
#define MUTEX_DEBUG_P(mtx) (((mtx)->mtx_owner & MUTEX_BIT_DEBUG) != 0)
#define MUTEX_DEBUG_P(mtx) (((mtx)->mtx_owner & MUTEX_BIT_NODEBUG) == 0)
#if defined(LOCKDEBUG)
#define MUTEX_OWNED(owner) (((owner) & ~MUTEX_BIT_DEBUG) != 0)
#define MUTEX_INHERITDEBUG(new, old) (new) |= (old) & MUTEX_BIT_DEBUG
#define MUTEX_OWNED(owner) (((owner) & ~MUTEX_BIT_NODEBUG) != 0)
#define MUTEX_INHERITDEBUG(new, old) (new) |= (old) & MUTEX_BIT_NODEBUG
#else /* defined(LOCKDEBUG) */
#define MUTEX_OWNED(owner) ((owner) != 0)
#define MUTEX_INHERITDEBUG(new, old) /* nothing */

View File

@ -1,4 +1,4 @@
/* $NetBSD: kern_rwlock.c,v 1.35 2010/02/06 04:50:19 cube Exp $ */
/* $NetBSD: kern_rwlock.c,v 1.36 2010/02/08 09:54:27 skrll Exp $ */
/*-
* Copyright (c) 2002, 2006, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: kern_rwlock.c,v 1.35 2010/02/06 04:50:19 cube Exp $");
__KERNEL_RCSID(0, "$NetBSD: kern_rwlock.c,v 1.36 2010/02/08 09:54:27 skrll Exp $");
#define __RWLOCK_PRIVATE
@ -103,10 +103,10 @@ do { \
#endif /* DIAGNOSTIC */
#define RW_SETDEBUG(rw, on) ((rw)->rw_owner |= (on) ? RW_DEBUG : 0)
#define RW_DEBUG_P(rw) (((rw)->rw_owner & RW_DEBUG) != 0)
#define RW_SETDEBUG(rw, on) ((rw)->rw_owner |= (on) ? 0 : RW_NODEBUG)
#define RW_DEBUG_P(rw) (((rw)->rw_owner & RW_NODEBUG) == 0)
#if defined(LOCKDEBUG)
#define RW_INHERITDEBUG(new, old) (new) |= (old) & RW_DEBUG
#define RW_INHERITDEBUG(new, old) (new) |= (old) & RW_NODEBUG
#else /* defined(LOCKDEBUG) */
#define RW_INHERITDEBUG(new, old) /* nothing */
#endif /* defined(LOCKDEBUG) */
@ -218,7 +218,7 @@ void
rw_destroy(krwlock_t *rw)
{
RW_ASSERT(rw, (rw->rw_owner & ~RW_DEBUG) == 0);
RW_ASSERT(rw, (rw->rw_owner & ~RW_NODEBUG) == 0);
LOCKDEBUG_FREE(RW_DEBUG_P(rw), rw);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: mutex.h,v 1.19 2010/02/06 04:50:19 cube Exp $ */
/* $NetBSD: mutex.h,v 1.20 2010/02/08 09:54:27 skrll Exp $ */
/*-
* Copyright (c) 2002, 2006, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@ -160,7 +160,12 @@ typedef struct kmutex kmutex_t;
#define MUTEX_BIT_SPIN 0x01
#define MUTEX_BIT_WAITERS 0x02
#define MUTEX_BIT_DEBUG 0x04
#if defined(LOCKDEBUG)
#define MUTEX_BIT_NODEBUG 0x04 /* LOCKDEBUG disabled */
#else
#define MUTEX_BIT_NODEBUG 0x00 /* do nothing */
#endif /* LOCKDEBUG */
#define MUTEX_SPIN_IPL(mtx) ((mtx)->mtx_ipl)
#define MUTEX_SPIN_OLDSPL(ci) ((ci)->ci_mtx_oldspl)

View File

@ -1,4 +1,4 @@
/* $NetBSD: rwlock.h,v 1.9 2010/02/06 04:50:19 cube Exp $ */
/* $NetBSD: rwlock.h,v 1.10 2010/02/08 09:54:27 skrll Exp $ */
/*-
* Copyright (c) 2002, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@ -67,15 +67,19 @@ typedef struct krwlock krwlock_t;
* WRITE_LOCKED bit is clear, then the owner field is actually a count of
* the number of readers. The rw_owner field is laid out like so:
*
* N 4 3 2 1 0
* +------------------------------------------------------+
* | owner or read count | debug | wrlock | wrwant | wait |
* +------------------------------------------------------+
* N 4 3 2 1 0
* +---------------------------------------------------------+
* | owner or read count | nodbug | wrlock | wrwant | wait |
* +---------------------------------------------------------+
*/
#define RW_HAS_WAITERS 0x01UL /* lock has waiters */
#define RW_WRITE_WANTED 0x02UL /* >= 1 waiter is a writer */
#define RW_WRITE_LOCKED 0x04UL /* lock is currently write locked */
#define RW_DEBUG 0x08UL /* LOCKDEBUG enabled */
#if defined(LOCKDEBUG)
#define RW_NODEBUG 0x08UL /* LOCKDEBUG disabled */
#else
#define RW_NODEBUG 0x00UL /* do nothing */
#endif /* LOCKDEBUG */
#define RW_READ_COUNT_SHIFT 4
#define RW_READ_INCR (1UL << RW_READ_COUNT_SHIFT)