Module Name:    src
Committed By:   jakllsch
Date:           Sat May 14 18:24:48 UTC 2011

Modified Files:
        src/sys/dev/dmover: dmover_backend.c dmover_request.c dmover_session.c

Log Message:
Convert remaining simplelock usage in dmover(4) to a RUN_ONCE(9).


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/dev/dmover/dmover_backend.c
cvs rdiff -u -r1.7 -r1.8 src/sys/dev/dmover/dmover_request.c
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/dmover/dmover_session.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/dmover/dmover_backend.c
diff -u src/sys/dev/dmover/dmover_backend.c:1.8 src/sys/dev/dmover/dmover_backend.c:1.9
--- src/sys/dev/dmover/dmover_backend.c:1.8	Sat Jan  5 02:47:03 2008
+++ src/sys/dev/dmover/dmover_backend.c	Sat May 14 18:24:47 2011
@@ -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);
-
-		/* Initialize the other bits of dmover. */
-		dmover_session_initialize();
-		dmover_request_initialize();
-		dmover_process_initialize();
+	KASSERT(initialized == false);
 
-		initialized = 1;
-	}
-	simple_unlock(&initialized_slock);
+	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();
+
+	initialized = true;
+
+	return 0;
 }
 
 /*
@@ -81,9 +80,11 @@
 void
 dmover_backend_register(struct dmover_backend *dmb)
 {
+	static ONCE_DECL(control);
+
+	RUN_ONCE(&control, initialize);
 
-	if (__predict_false(initialized == 0))
-		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);

Index: src/sys/dev/dmover/dmover_request.c
diff -u src/sys/dev/dmover/dmover_request.c:1.7 src/sys/dev/dmover/dmover_request.c:1.8
--- src/sys/dev/dmover/dmover_request.c:1.7	Fri Jan  4 21:17:52 2008
+++ src/sys/dev/dmover/dmover_request.c	Sat May 14 18:24:47 2011
@@ -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);
 

Index: src/sys/dev/dmover/dmover_session.c
diff -u src/sys/dev/dmover/dmover_session.c:1.5 src/sys/dev/dmover/dmover_session.c:1.6
--- src/sys/dev/dmover/dmover_session.c:1.5	Fri Jan  4 21:17:52 2008
+++ src/sys/dev/dmover/dmover_session.c	Sat May 14 18:24:47 2011
@@ -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)

Reply via email to