Module Name:    src
Committed By:   mrg
Date:           Tue Nov 22 08:55:44 UTC 2011

Modified Files:
        src/sys/dev [jmcneill-audiomp3]: midictl.c

Log Message:
- make this not crash with "midiplay -l" anymore by killing store_thread()
  with kthread_exit() instead of return

- adjust wait channels to be unique

- add some asserts that insert it not called while destroy is in progress

- note some probably dead code with KASSERT(FALSE) for now


To generate a diff of this commit:
cvs rdiff -u -r1.6.32.2 -r1.6.32.3 src/sys/dev/midictl.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/midictl.c
diff -u src/sys/dev/midictl.c:1.6.32.2 src/sys/dev/midictl.c:1.6.32.3
--- src/sys/dev/midictl.c:1.6.32.2	Tue Nov 22 06:11:12 2011
+++ src/sys/dev/midictl.c	Tue Nov 22 08:55:44 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: midictl.c,v 1.6.32.2 2011/11/22 06:11:12 mrg Exp $ */
+/* $NetBSD: midictl.c,v 1.6.32.3 2011/11/22 08:55:44 mrg Exp $ */
 
 /*-
  * Copyright (c) 2006, 2008 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: midictl.c,v 1.6.32.2 2011/11/22 06:11:12 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: midictl.c,v 1.6.32.3 2011/11/22 08:55:44 mrg Exp $");
 
 /*
  * See midictl.h for an overview of the purpose and use of this module.
@@ -188,9 +188,9 @@ midictl_open(midictl *mc)
 		return ENOMEM;
 	}
 	s->lock = mc->lock;
-	cv_init(&s->cv, "midictl");
+	cv_init(&s->cv, "midictlv");
 	error = kthread_create(PRI_NONE, KTHREAD_MPSAFE, NULL, store_thread, 
-	    s, NULL, "midictl");
+	    s, NULL, "midictlt");
 	if (error != 0) {
 		printf("midictl: cannot create kthread, error = %d\n", error);
 		cv_destroy(&s->cv);
@@ -225,6 +225,7 @@ midictl_change(midictl *mc, uint_fast8_t
 	_Bool islsb, present;
 
 	KASSERT(mutex_owned(mc->lock));
+	KASSERT(!mc->store->destroy);
 		
 	switch ( ctlval[0] ) {
 	/*
@@ -352,6 +353,7 @@ midictl_read(midictl *mc, uint_fast8_t c
 	_Bool islsb, present;
 
 	KASSERT(mutex_owned(mc->lock));
+	KASSERT(!mc->store->destroy);
 	
 	key = ctlr;
 	c = classify(&key, &islsb);
@@ -388,6 +390,7 @@ midictl_rpn_read(midictl *mc, uint_fast8
 {
 
 	KASSERT(mutex_owned(mc->lock));
+	KASSERT(!mc->store->destroy);
 
 	return read14(mc, chan, RPN, ctlr, dflt);
 }
@@ -398,6 +401,7 @@ midictl_nrpn_read(midictl *mc, uint_fast
 {
 
 	KASSERT(mutex_owned(mc->lock));
+	KASSERT(!mc->store->destroy);
 
 	return read14(mc, chan, NRPN, ctlr, dflt);
 }
@@ -550,7 +554,7 @@ store_thread(void *arg)
 			cv_destroy(&s->cv);
 			kmem_free(s->table, sizeof(*s->table)<<s->lgcapacity);
 			kmem_free(s, sizeof(*s));
-			return;
+			kthread_exit(0);
 		} else if (NEED_REHASH(s)) {
 			store_rehash(s);
 		} else {
@@ -689,20 +693,28 @@ store_rehash(midictl_store *s)
 	mutex_enter(s->lock);
 
 	if (newtbl == NULL) {
-		kpause("midictl", false, hz, s->lock);
+		kpause("midictls", false, hz, s->lock);
 		return;
 	}
+	/*
+	 * If s->lgcapacity is changed from what we saved int oldlgcap
+	 * then someone else has already done this for us.
+	 * XXXMRG but only function changes s->lgcapacity from its
+	 * initial value, and it is called singled threaded from the
+	 * main store_thread(), so this code seems dead to me.
+	 */
 	if (oldlgcap != s->lgcapacity) {
+		KASSERT(FALSE);
 		mutex_exit(s->lock);
 		kmem_free(newtbl, sizeof(*newtbl) << newlgcap);
 		mutex_enter(s->lock);
 		return;
 	}
 			
-	for ( oidx = 1<<s->lgcapacity ; oidx --> 0 ; ) {
-		if (!(s->table[oidx] & IS_USED) )
+	for (oidx = 1 << s->lgcapacity ; oidx-- > 0 ; ) {
+		if (!(s->table[oidx] & IS_USED))
 			continue;
-		if ( s->table[oidx] & IS_CTL7 )
+		if (s->table[oidx] & IS_CTL7)
 			mask = 0xffff;
 		else
 			mask = 0x3fffff;

Reply via email to