Source-Changes-HG archive

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

[src/jmcneill-audiomp3]: src/sys/dev change the locking protocol for audio_ge...



details:   https://anonhg.NetBSD.org/src/rev/bdefb0570c5f
branches:  jmcneill-audiomp3
changeset: 771336:bdefb0570c5f
user:      mrg <mrg%NetBSD.org@localhost>
date:      Sun Nov 20 10:58:10 2011 +0000

description:
change the locking protocol for audio_get_props().  make it always
assert that the thread lock is held before entry, and arrange to
make this always so.

diffstat:

 sys/dev/audio.c |  21 ++++++++++++++++-----
 1 files changed, 16 insertions(+), 5 deletions(-)

diffs (76 lines):

diff -r 0f70daeb74eb -r bdefb0570c5f sys/dev/audio.c
--- a/sys/dev/audio.c   Sun Nov 20 10:56:18 2011 +0000
+++ b/sys/dev/audio.c   Sun Nov 20 10:58:10 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: audio.c,v 1.253.4.1 2011/11/19 21:49:34 jmcneill Exp $ */
+/*     $NetBSD: audio.c,v 1.253.4.2 2011/11/20 10:58:10 mrg Exp $      */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -155,7 +155,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.253.4.1 2011/11/19 21:49:34 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.253.4.2 2011/11/20 10:58:10 mrg Exp $");
 
 #include "audio.h"
 #if NAUDIO > 0
@@ -430,7 +430,9 @@
        sc->sc_dev = parent;
        sc->sc_lastinfovalid = false;
 
+       mutex_enter(sc->sc_lock);
        props = audio_get_props(sc);
+       mutex_exit(sc->sc_lock);
 
        if (props & AUDIO_PROP_FULLDUPLEX)
                aprint_normal(": full duplex");
@@ -449,6 +451,14 @@
        aprint_naive("\n");
        aprint_normal("\n");
 
+       /*
+        * XXX  Would like to not hold the sc_lock around this whole block
+        * escpially for audio_alloc_ring(), except that the latter calls
+        * ->round_blocksize() which demands the thread lock to be taken.
+        *
+        * Revisit.
+        */
+       mutex_enter(sc->sc_lock);
        if (audio_can_playback(sc)) {
                error = audio_alloc_ring(sc, &sc->sc_pr,
                    AUMODE_PLAY, AU_RING_SIZE);
@@ -472,7 +482,6 @@
 
        sc->sc_lastgain = 128;
 
-       mutex_enter(sc->sc_lock);
        error = audio_set_defaults(sc, 0);
        mutex_exit(sc->sc_lock);
        if (error != 0) {
@@ -1663,9 +1672,11 @@
        sc->sc_eof = 0;
        sc->sc_playdrop = 0;
 
+       mutex_enter(sc->sc_intr_lock);
        sc->sc_full_duplex = 
                (flags & (FWRITE|FREAD)) == (FWRITE|FREAD) &&
                (audio_get_props(sc) & AUDIO_PROP_FULLDUPLEX);
+       mutex_exit(sc->sc_intr_lock);
 
        mode = 0;
        if (flags & FREAD) {
@@ -4416,10 +4427,10 @@
        const struct audio_hw_if *hw;
        int props;
 
+       KASSERT(mutex_owned(sc->sc_lock));
+
        hw = sc->hw_if;
-       mutex_enter(sc->sc_lock);
        props = hw->get_props(sc->hw_hdl);
-       mutex_exit(sc->sc_lock);
 
        /*
         * if neither playback nor capture properties are reported,



Home | Main Index | Thread Index | Old Index