Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Heave-ho mutex/rwlock object routines into separate modu...
details: https://anonhg.NetBSD.org/src/rev/d8b17f74b127
branches: trunk
changeset: 748743:d8b17f74b127
user: pooka <pooka%NetBSD.org@localhost>
date: Wed Nov 04 13:29:45 2009 +0000
description:
Heave-ho mutex/rwlock object routines into separate modules -- they
don't have anything to do with the lock internals.
diffstat:
sys/conf/files | 4 +-
sys/kern/kern_mutex.c | 104 +---------------------------------
sys/kern/kern_mutex_obj.c | 135 +++++++++++++++++++++++++++++++++++++++++++++
sys/kern/kern_rwlock.c | 101 +---------------------------------
sys/kern/kern_rwlock_obj.c | 135 +++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 278 insertions(+), 201 deletions(-)
diffs (truncated from 569 to 300 lines):
diff -r d8c592b57c6f -r d8b17f74b127 sys/conf/files
--- a/sys/conf/files Wed Nov 04 12:58:01 2009 +0000
+++ b/sys/conf/files Wed Nov 04 13:29:45 2009 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files,v 1.960 2009/11/03 00:24:05 dyoung Exp $
+# $NetBSD: files,v 1.961 2009/11/04 13:29:45 pooka Exp $
# @(#)files.newconf 7.5 (Berkeley) 5/10/93
version 20090313
@@ -1439,6 +1439,7 @@
file kern/kern_malloc_debug.c malloc_debug
file kern/kern_module.c
file kern/kern_mutex.c
+file kern/kern_mutex_obj.c
file kern/kern_fileassoc.c fileassoc
file kern/kern_ntptime.c
file kern/kern_pax.c pax_mprotect | pax_segvguard
@@ -1451,6 +1452,7 @@
file kern/kern_resource.c
file kern/kern_runq.c
file kern/kern_rwlock.c
+file kern/kern_rwlock_obj.c
file kern/kern_sig.c
file kern/kern_sleepq.c
file kern/kern_softint.c
diff -r d8c592b57c6f -r d8b17f74b127 sys/kern/kern_mutex.c
--- a/sys/kern/kern_mutex.c Wed Nov 04 12:58:01 2009 +0000
+++ b/sys/kern/kern_mutex.c Wed Nov 04 13:29:45 2009 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_mutex.c,v 1.45 2009/01/25 04:45:14 rmind Exp $ */
+/* $NetBSD: kern_mutex.c,v 1.46 2009/11/04 13:29:45 pooka Exp $ */
/*-
* Copyright (c) 2002, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -40,9 +40,10 @@
#define __MUTEX_PRIVATE
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_mutex.c,v 1.45 2009/01/25 04:45:14 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_mutex.c,v 1.46 2009/11/04 13:29:45 pooka Exp $");
#include <sys/param.h>
+#include <sys/atomic.h>
#include <sys/proc.h>
#include <sys/mutex.h>
#include <sys/sched.h>
@@ -50,10 +51,8 @@
#include <sys/systm.h>
#include <sys/lockdebug.h>
#include <sys/kernel.h>
-#include <sys/atomic.h>
#include <sys/intr.h>
#include <sys/lock.h>
-#include <sys/pool.h>
#include <dev/lockstat.h>
@@ -274,18 +273,6 @@
(void *)mutex_owner,
};
-/* Mutex cache */
-#define MUTEX_OBJ_MAGIC 0x5aa3c85d
-struct kmutexobj {
- kmutex_t mo_lock;
- u_int mo_magic;
- u_int mo_refcnt;
-};
-
-static int mutex_obj_ctor(void *, void *, int);
-
-static pool_cache_t mutex_obj_cache;
-
/*
* mutex_dump:
*
@@ -940,88 +927,3 @@
#endif /* MULTIPROCESSOR */
}
#endif /* defined(__HAVE_SPIN_MUTEX_STUBS) || defined(FULL) */
-
-/*
- * mutex_obj_init:
- *
- * Initialize the mutex object store.
- */
-void
-mutex_obj_init(void)
-{
-
- mutex_obj_cache = pool_cache_init(sizeof(struct kmutexobj),
- coherency_unit, 0, 0, "mutex", NULL, IPL_NONE, mutex_obj_ctor,
- NULL, NULL);
-}
-
-/*
- * mutex_obj_ctor:
- *
- * Initialize a new lock for the cache.
- */
-static int
-mutex_obj_ctor(void *arg, void *obj, int flags)
-{
- struct kmutexobj * mo = obj;
-
- mo->mo_magic = MUTEX_OBJ_MAGIC;
-
- return 0;
-}
-
-/*
- * mutex_obj_alloc:
- *
- * Allocate a single lock object.
- */
-kmutex_t *
-mutex_obj_alloc(kmutex_type_t type, int ipl)
-{
- struct kmutexobj *mo;
-
- mo = pool_cache_get(mutex_obj_cache, PR_WAITOK);
- mutex_init(&mo->mo_lock, type, ipl);
- mo->mo_refcnt = 1;
-
- return (kmutex_t *)mo;
-}
-
-/*
- * mutex_obj_hold:
- *
- * Add a single reference to a lock object. A reference to the object
- * must already be held, and must be held across this call.
- */
-void
-mutex_obj_hold(kmutex_t *lock)
-{
- struct kmutexobj *mo = (struct kmutexobj *)lock;
-
- KASSERT(mo->mo_magic == MUTEX_OBJ_MAGIC);
- KASSERT(mo->mo_refcnt > 0);
-
- atomic_inc_uint(&mo->mo_refcnt);
-}
-
-/*
- * mutex_obj_free:
- *
- * Drop a reference from a lock object. If the last reference is being
- * dropped, free the object and return true. Otherwise, return false.
- */
-bool
-mutex_obj_free(kmutex_t *lock)
-{
- struct kmutexobj *mo = (struct kmutexobj *)lock;
-
- KASSERT(mo->mo_magic == MUTEX_OBJ_MAGIC);
- KASSERT(mo->mo_refcnt > 0);
-
- if (atomic_dec_uint_nv(&mo->mo_refcnt) > 0) {
- return false;
- }
- mutex_destroy(&mo->mo_lock);
- pool_cache_put(mutex_obj_cache, mo);
- return true;
-}
diff -r d8c592b57c6f -r d8b17f74b127 sys/kern/kern_mutex_obj.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/kern/kern_mutex_obj.c Wed Nov 04 13:29:45 2009 +0000
@@ -0,0 +1,135 @@
+/* $NetBSD: kern_mutex_obj.c,v 1.1 2009/11/04 13:29:45 pooka Exp $ */
+
+/*-
+ * Copyright (c) 2002, 2006, 2007, 2008 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jason R. Thorpe and Andrew Doran.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: kern_mutex_obj.c,v 1.1 2009/11/04 13:29:45 pooka Exp $");
+
+#include <sys/param.h>
+#include <sys/atomic.h>
+#include <sys/mutex.h>
+#include <sys/pool.h>
+
+/* Mutex cache */
+#define MUTEX_OBJ_MAGIC 0x5aa3c85d
+struct kmutexobj {
+ kmutex_t mo_lock;
+ u_int mo_magic;
+ u_int mo_refcnt;
+};
+
+static int mutex_obj_ctor(void *, void *, int);
+
+static pool_cache_t mutex_obj_cache;
+
+/*
+ * mutex_obj_init:
+ *
+ * Initialize the mutex object store.
+ */
+void
+mutex_obj_init(void)
+{
+
+ mutex_obj_cache = pool_cache_init(sizeof(struct kmutexobj),
+ coherency_unit, 0, 0, "mutex", NULL, IPL_NONE, mutex_obj_ctor,
+ NULL, NULL);
+}
+
+/*
+ * mutex_obj_ctor:
+ *
+ * Initialize a new lock for the cache.
+ */
+static int
+mutex_obj_ctor(void *arg, void *obj, int flags)
+{
+ struct kmutexobj * mo = obj;
+
+ mo->mo_magic = MUTEX_OBJ_MAGIC;
+
+ return 0;
+}
+
+/*
+ * mutex_obj_alloc:
+ *
+ * Allocate a single lock object.
+ */
+kmutex_t *
+mutex_obj_alloc(kmutex_type_t type, int ipl)
+{
+ struct kmutexobj *mo;
+
+ mo = pool_cache_get(mutex_obj_cache, PR_WAITOK);
+ mutex_init(&mo->mo_lock, type, ipl);
+ mo->mo_refcnt = 1;
+
+ return (kmutex_t *)mo;
+}
+
+/*
+ * mutex_obj_hold:
+ *
+ * Add a single reference to a lock object. A reference to the object
+ * must already be held, and must be held across this call.
+ */
+void
+mutex_obj_hold(kmutex_t *lock)
+{
+ struct kmutexobj *mo = (struct kmutexobj *)lock;
+
+ KASSERT(mo->mo_magic == MUTEX_OBJ_MAGIC);
+ KASSERT(mo->mo_refcnt > 0);
+
+ atomic_inc_uint(&mo->mo_refcnt);
+}
+
+/*
+ * mutex_obj_free:
+ *
+ * Drop a reference from a lock object. If the last reference is being
+ * dropped, free the object and return true. Otherwise, return false.
+ */
+bool
+mutex_obj_free(kmutex_t *lock)
+{
+ struct kmutexobj *mo = (struct kmutexobj *)lock;
+
+ KASSERT(mo->mo_magic == MUTEX_OBJ_MAGIC);
+ KASSERT(mo->mo_refcnt > 0);
+
+ if (atomic_dec_uint_nv(&mo->mo_refcnt) > 0) {
+ return false;
+ }
Home |
Main Index |
Thread Index |
Old Index