Sat Jun 11 01:07:33 2011 UTC ()
Use KASSERTMSG so if these trigger, we can see what exactly caused them to fire.


(matt)
diff -r1.3 -r1.4 src/sys/kern/kern_mutex_obj.c

cvs diff -r1.3 -r1.4 src/sys/kern/kern_mutex_obj.c (expand / switch to unified diff)

--- src/sys/kern/kern_mutex_obj.c 2011/05/13 22:16:43 1.3
+++ src/sys/kern/kern_mutex_obj.c 2011/06/11 01:07:33 1.4
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: kern_mutex_obj.c,v 1.3 2011/05/13 22:16:43 rmind Exp $ */ 1/* $NetBSD: kern_mutex_obj.c,v 1.4 2011/06/11 01:07:33 matt Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2008 The NetBSD Foundation, Inc. 4 * Copyright (c) 2008 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Andrew Doran. 8 * by Andrew Doran.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -20,27 +20,27 @@ @@ -20,27 +20,27 @@
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33__KERNEL_RCSID(0, "$NetBSD: kern_mutex_obj.c,v 1.3 2011/05/13 22:16:43 rmind Exp $"); 33__KERNEL_RCSID(0, "$NetBSD: kern_mutex_obj.c,v 1.4 2011/06/11 01:07:33 matt Exp $");
34 34
35#include <sys/param.h> 35#include <sys/param.h>
36#include <sys/atomic.h> 36#include <sys/atomic.h>
37#include <sys/mutex.h> 37#include <sys/mutex.h>
38#include <sys/pool.h> 38#include <sys/pool.h>
39 39
40/* Mutex cache */ 40/* Mutex cache */
41#define MUTEX_OBJ_MAGIC 0x5aa3c85d 41#define MUTEX_OBJ_MAGIC 0x5aa3c85d
42struct kmutexobj { 42struct kmutexobj {
43 kmutex_t mo_lock; 43 kmutex_t mo_lock;
44 u_int mo_magic; 44 u_int mo_magic;
45 u_int mo_refcnt; 45 u_int mo_refcnt;
46}; 46};
@@ -96,40 +96,48 @@ mutex_obj_alloc(kmutex_type_t type, int  @@ -96,40 +96,48 @@ mutex_obj_alloc(kmutex_type_t type, int
96} 96}
97 97
98/* 98/*
99 * mutex_obj_hold: 99 * mutex_obj_hold:
100 * 100 *
101 * Add a single reference to a lock object. A reference to the object 101 * Add a single reference to a lock object. A reference to the object
102 * must already be held, and must be held across this call. 102 * must already be held, and must be held across this call.
103 */ 103 */
104void 104void
105mutex_obj_hold(kmutex_t *lock) 105mutex_obj_hold(kmutex_t *lock)
106{ 106{
107 struct kmutexobj *mo = (struct kmutexobj *)lock; 107 struct kmutexobj *mo = (struct kmutexobj *)lock;
108 108
109 KASSERT(mo->mo_magic == MUTEX_OBJ_MAGIC); 109 KASSERTMSG(mo->mo_magic == MUTEX_OBJ_MAGIC,
110 KASSERT(mo->mo_refcnt > 0); 110 ("%s: lock %p: mo->mo_magic (%#x) != MUTEX_OBJ_MAGIC (%#x)",
 111 __func__, mo, mo->mo_magic, MUTEX_OBJ_MAGIC));
 112 KASSERTMSG(mo->mo_refcnt > 0,
 113 ("%s: lock %p: mo->mo_refcnt (%#x) == 0",
 114 __func__, mo, mo->mo_refcnt));
111 115
112 atomic_inc_uint(&mo->mo_refcnt); 116 atomic_inc_uint(&mo->mo_refcnt);
113} 117}
114 118
115/* 119/*
116 * mutex_obj_free: 120 * mutex_obj_free:
117 * 121 *
118 * Drop a reference from a lock object. If the last reference is being 122 * Drop a reference from a lock object. If the last reference is being
119 * dropped, free the object and return true. Otherwise, return false. 123 * dropped, free the object and return true. Otherwise, return false.
120 */ 124 */
121bool 125bool
122mutex_obj_free(kmutex_t *lock) 126mutex_obj_free(kmutex_t *lock)
123{ 127{
124 struct kmutexobj *mo = (struct kmutexobj *)lock; 128 struct kmutexobj *mo = (struct kmutexobj *)lock;
125 129
126 KASSERT(mo->mo_magic == MUTEX_OBJ_MAGIC); 130 KASSERTMSG(mo->mo_magic == MUTEX_OBJ_MAGIC,
127 KASSERT(mo->mo_refcnt > 0); 131 ("%s: lock %p: mo->mo_magic (%#x) != MUTEX_OBJ_MAGIC (%#x)",
 132 __func__, mo, mo->mo_magic, MUTEX_OBJ_MAGIC));
 133 KASSERTMSG(mo->mo_refcnt > 0,
 134 ("%s: lock %p: mo->mo_refcnt (%#x) == 0",
 135 __func__, mo, mo->mo_refcnt));
128 136
129 if (atomic_dec_uint_nv(&mo->mo_refcnt) > 0) { 137 if (atomic_dec_uint_nv(&mo->mo_refcnt) > 0) {
130 return false; 138 return false;
131 } 139 }
132 mutex_destroy(&mo->mo_lock); 140 mutex_destroy(&mo->mo_lock);
133 pool_cache_put(mutex_obj_cache, mo); 141 pool_cache_put(mutex_obj_cache, mo);
134 return true; 142 return true;
135} 143}