Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev midi(4): Wake waiters _before_ waiting for them.



details:   https://anonhg.NetBSD.org/src/rev/bdb25162b356
branches:  trunk
changeset: 371982:bdb25162b356
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sun Oct 23 23:02:50 2022 +0000

description:
midi(4): Wake waiters _before_ waiting for them.

Otherwise we may deadlock waiting for them to give up while they're
waiting for I/O, not knowing they need to give up.

diffstat:

 sys/dev/midi.c |  9 ++++-----
 1 files changed, 4 insertions(+), 5 deletions(-)

diffs (34 lines):

diff -r 452fc2a06b09 -r bdb25162b356 sys/dev/midi.c
--- a/sys/dev/midi.c    Sun Oct 23 15:43:40 2022 +0000
+++ b/sys/dev/midi.c    Sun Oct 23 23:02:50 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: midi.c,v 1.98 2022/06/04 03:31:10 pgoyette Exp $       */
+/*     $NetBSD: midi.c,v 1.99 2022/10/23 23:02:50 riastradh Exp $      */
 
 /*
  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: midi.c,v 1.98 2022/06/04 03:31:10 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: midi.c,v 1.99 2022/10/23 23:02:50 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "midi.h"
@@ -206,13 +206,12 @@
 
        mutex_enter(sc->lock);
        sc->dying = 1;
+       cv_broadcast(&sc->wchan);
+       cv_broadcast(&sc->rchan);
 
        if (--sc->refcnt >= 0) {
-               /* Wake anything? */
                (void)cv_timedwait(&sc->detach_cv, sc->lock, hz * 60);
        }
-       cv_broadcast(&sc->wchan);
-       cv_broadcast(&sc->rchan);
        mutex_exit(sc->lock);
 
        /* locate the major number */



Home | Main Index | Thread Index | Old Index