Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Re-apply:



details:   https://anonhg.NetBSD.org/src/rev/4e101496b303
branches:  trunk
changeset: 751912:4e101496b303
user:      skrll <skrll%NetBSD.org@localhost>
date:      Mon Feb 08 09:54:27 2010 +0000

description:
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.

diffstat:

 sys/kern/kern_mutex.c  |  18 +++++++++---------
 sys/kern/kern_rwlock.c |  12 ++++++------
 sys/sys/mutex.h        |   9 +++++++--
 sys/sys/rwlock.h       |  16 ++++++++++------
 4 files changed, 32 insertions(+), 23 deletions(-)

diffs (151 lines):

diff -r 6eb264e09593 -r 4e101496b303 sys/kern/kern_mutex.c
--- a/sys/kern/kern_mutex.c     Mon Feb 08 08:49:57 2010 +0000
+++ b/sys/kern/kern_mutex.c     Mon Feb 08 09:54:27 2010 +0000
@@ -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 @@
        (((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 @@
 #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 */
diff -r 6eb264e09593 -r 4e101496b303 sys/kern/kern_rwlock.c
--- a/sys/kern/kern_rwlock.c    Mon Feb 08 08:49:57 2010 +0000
+++ b/sys/kern/kern_rwlock.c    Mon Feb 08 09:54:27 2010 +0000
@@ -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 @@
 
 #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 @@
 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);
 }
 
diff -r 6eb264e09593 -r 4e101496b303 sys/sys/mutex.h
--- a/sys/sys/mutex.h   Mon Feb 08 08:49:57 2010 +0000
+++ b/sys/sys/mutex.h   Mon Feb 08 09:54:27 2010 +0000
@@ -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 @@
 
 #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)
diff -r 6eb264e09593 -r 4e101496b303 sys/sys/rwlock.h
--- a/sys/sys/rwlock.h  Mon Feb 08 08:49:57 2010 +0000
+++ b/sys/sys/rwlock.h  Mon Feb 08 09:54:27 2010 +0000
@@ -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 @@
  * 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)



Home | Main Index | Thread Index | Old Index