Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/dmover Convert remaining simplelock usage in dmover(...
details: https://anonhg.NetBSD.org/src/rev/0195995533d5
branches: trunk
changeset: 764973:0195995533d5
user: jakllsch <jakllsch%NetBSD.org@localhost>
date: Sat May 14 18:24:47 2011 +0000
description:
Convert remaining simplelock usage in dmover(4) to a RUN_ONCE(9).
diffstat:
sys/dev/dmover/dmover_backend.c | 63 ++++++++++++++--------------------------
sys/dev/dmover/dmover_request.c | 37 +++++++----------------
sys/dev/dmover/dmover_session.c | 39 +++++++------------------
3 files changed, 45 insertions(+), 94 deletions(-)
diffs (281 lines):
diff -r 9bcfdef6cebd -r 0195995533d5 sys/dev/dmover/dmover_backend.c
--- a/sys/dev/dmover/dmover_backend.c Sat May 14 17:57:05 2011 +0000
+++ b/sys/dev/dmover/dmover_backend.c Sat May 14 18:24:47 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: dmover_backend.c,v 1.8 2008/01/05 02:47:03 matt Exp $ */
+/* $NetBSD: dmover_backend.c,v 1.9 2011/05/14 18:24:47 jakllsch Exp $ */
/*
* Copyright (c) 2002 Wasabi Systems, Inc.
@@ -40,37 +40,36 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: dmover_backend.c,v 1.8 2008/01/05 02:47:03 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dmover_backend.c,v 1.9 2011/05/14 18:24:47 jakllsch Exp $");
#include <sys/param.h>
#include <sys/mutex.h>
-#include <sys/simplelock.h>
#include <sys/systm.h>
+#include <sys/once.h>
#include <dev/dmover/dmovervar.h>
TAILQ_HEAD(, dmover_backend) dmover_backend_list;
kmutex_t dmover_backend_list_lock;
-static int initialized;
-static struct simplelock initialized_slock = SIMPLELOCK_INITIALIZER;
+static bool initialized;
-static void
+static int
initialize(void)
{
- simple_lock(&initialized_slock);
- if (__predict_true(initialized == 0)) {
- TAILQ_INIT(&dmover_backend_list);
- mutex_init(&dmover_backend_list_lock, MUTEX_DEFAULT, IPL_VM);
+ KASSERT(initialized == false);
+
+ TAILQ_INIT(&dmover_backend_list);
+ mutex_init(&dmover_backend_list_lock, MUTEX_DEFAULT, IPL_VM);
- /* Initialize the other bits of dmover. */
- dmover_session_initialize();
- dmover_request_initialize();
- dmover_process_initialize();
+ /* Initialize the other bits of dmover. */
+ dmover_session_initialize();
+ dmover_request_initialize();
+ dmover_process_initialize();
- initialized = 1;
- }
- simple_unlock(&initialized_slock);
+ initialized = true;
+
+ return 0;
}
/*
@@ -81,9 +80,11 @@
void
dmover_backend_register(struct dmover_backend *dmb)
{
+ static ONCE_DECL(control);
- if (__predict_false(initialized == 0))
- initialize();
+ RUN_ONCE(&control, initialize);
+
+ KASSERT(initialized == true);
LIST_INIT(&dmb->dmb_sessions);
dmb->dmb_nsessions = 0;
@@ -105,18 +106,7 @@
dmover_backend_unregister(struct dmover_backend *dmb)
{
-#ifdef DIAGNOSTIC
- if (__predict_false(initialized == 0)) {
- int croak;
-
- simple_lock(&initialized_slock);
- croak = (initialized == 0);
- simple_unlock(&initialized_slock);
-
- if (croak)
- panic("dmover_backend_unregister: not initialized");
- }
-#endif
+ KASSERT(initialized == true);
/* XXX */
if (dmb->dmb_nsessions)
@@ -138,15 +128,8 @@
struct dmover_backend *dmb, *best_dmb = NULL;
const struct dmover_algdesc *algdesc, *best_algdesc = NULL;
- if (__predict_false(initialized == 0)) {
- int fail;
-
- simple_lock(&initialized_slock);
- fail = (initialized == 0);
- simple_unlock(&initialized_slock);
-
- if (fail)
- return (ESRCH);
+ if (__predict_false(initialized == false)) {
+ return (ESRCH);
}
mutex_enter(&dmover_backend_list_lock);
diff -r 9bcfdef6cebd -r 0195995533d5 sys/dev/dmover/dmover_request.c
--- a/sys/dev/dmover/dmover_request.c Sat May 14 17:57:05 2011 +0000
+++ b/sys/dev/dmover/dmover_request.c Sat May 14 18:24:47 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: dmover_request.c,v 1.7 2008/01/04 21:17:52 ad Exp $ */
+/* $NetBSD: dmover_request.c,v 1.8 2011/05/14 18:24:47 jakllsch Exp $ */
/*
* Copyright (c) 2002 Wasabi Systems, Inc.
@@ -40,10 +40,9 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: dmover_request.c,v 1.7 2008/01/04 21:17:52 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dmover_request.c,v 1.8 2011/05/14 18:24:47 jakllsch Exp $");
#include <sys/param.h>
-#include <sys/simplelock.h>
#include <sys/pool.h>
#include <sys/systm.h>
#include <sys/malloc.h>
@@ -52,40 +51,24 @@
pool_cache_t dmover_request_cache;
-static int initialized;
-static struct simplelock initialized_slock = SIMPLELOCK_INITIALIZER;
+static bool initialized;
void
dmover_request_initialize(void)
{
- pool_cache_t pc;
- int s;
- if (initialized == 0) {
- pc = pool_cache_init(sizeof(struct dmover_request), 0, 0, 0,
- "dmreq", NULL, IPL_BIO, NULL, NULL, NULL);
- } else {
- pc = NULL;
- }
+ KASSERT(initialized == false);
- s = splbio();
- simple_lock(&initialized_slock);
- if (__predict_true(initialized == 0)) {
- dmover_request_cache = pc;
- pc = NULL;
- initialized = 1;
- }
- simple_unlock(&initialized_slock);
- splx(s);
+ dmover_request_cache = pool_cache_init(sizeof(struct dmover_request),
+ 0, 0, 0, "dmreq", NULL, IPL_BIO, NULL, NULL, NULL);
- if (pc != NULL)
- pool_cache_destroy(pc);
+ initialized = true;
}
/*
* dmover_request_alloc: [client interface function]
*
- * Allocate a tranform request for the specified session.
+ * Allocate a transform request for the specified session.
*/
struct dmover_request *
dmover_request_alloc(struct dmover_session *dses, dmover_buffer *inbuf)
@@ -93,7 +76,7 @@
struct dmover_request *dreq;
int inputs = dses->dses_ninputs;
- if (__predict_false(initialized == 0))
+ if (__predict_false(initialized == false))
return (NULL);
dreq = pool_cache_get(dmover_request_cache, PR_NOWAIT);
@@ -129,6 +112,8 @@
dmover_request_free(struct dmover_request *dreq)
{
+ KASSERT(initialized == true);
+
if (dreq->dreq_flags & __DMOVER_REQ_INBUF_FREE)
free(dreq->dreq_inbuf, M_DEVBUF);
diff -r 9bcfdef6cebd -r 0195995533d5 sys/dev/dmover/dmover_session.c
--- a/sys/dev/dmover/dmover_session.c Sat May 14 17:57:05 2011 +0000
+++ b/sys/dev/dmover/dmover_session.c Sat May 14 18:24:47 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: dmover_session.c,v 1.5 2008/01/04 21:17:52 ad Exp $ */
+/* $NetBSD: dmover_session.c,v 1.6 2011/05/14 18:24:47 jakllsch Exp $ */
/*
* Copyright (c) 2002 Wasabi Systems, Inc.
@@ -40,10 +40,9 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: dmover_session.c,v 1.5 2008/01/04 21:17:52 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dmover_session.c,v 1.6 2011/05/14 18:24:47 jakllsch Exp $");
#include <sys/param.h>
-#include <sys/simplelock.h>
#include <sys/pool.h>
#include <sys/systm.h>
#include <sys/malloc.h>
@@ -52,20 +51,17 @@
struct pool dmover_session_pool;
-static int initialized;
-static struct simplelock initialized_slock = SIMPLELOCK_INITIALIZER;
+static bool initialized;
void
dmover_session_initialize(void)
{
- simple_lock(&initialized_slock);
- if (__predict_true(initialized == 0)) {
- pool_init(&dmover_session_pool, sizeof(struct dmover_session),
- 0, 0, 0, "dmses", &pool_allocator_nointr, IPL_NONE);
- initialized = 1;
- }
- simple_unlock(&initialized_slock);
+ KASSERT(initialized == false);
+
+ pool_init(&dmover_session_pool, sizeof(struct dmover_session),
+ 0, 0, 0, "dmses", &pool_allocator_nointr, IPL_NONE);
+ initialized = true;
}
/*
@@ -79,10 +75,8 @@
struct dmover_session *dses;
int error;
- if (__predict_false(initialized == 0)) {
- simple_lock(&initialized_slock);
- error = initialized ? 0 : ENXIO;
- simple_unlock(&initialized_slock);
+ if (__predict_false(initialized == false)) {
+ error = initialized ? false : ENXIO;
if (error)
return (error);
@@ -115,18 +109,7 @@
dmover_session_destroy(struct dmover_session *dses)
{
-#ifdef DIAGNOSTIC
- if (__predict_false(initialized == 0)) {
- int croak;
-
- simple_lock(&initialized_slock);
- croak = (initialized == 0);
- simple_unlock(&initialized_slock);
-
- if (croak)
- panic("dmover_session_destroy: not initialized");
- }
-#endif
+ KASSERT(initialized == true);
/* XXX */
if (dses->__dses_npendreqs)
Home |
Main Index |
Thread Index |
Old Index