--- sys/dev/sound/pcm/sound.h.orig Thu Sep 15 11:25:29 2005 +++ sys/dev/sound/pcm/sound.h Thu Sep 15 11:31:19 2005 @@ -238,11 +238,12 @@ int sysctl_hw_snd_vchans(SYSCTL_HANDLER_ARGS); typedef int (*sndstat_handler)(struct sbuf *s, device_t dev, int verbose); +int sndstat_acquire(void); +int sndstat_release(void); int sndstat_register(device_t dev, char *str, sndstat_handler handler); int sndstat_registerfile(char *str); int sndstat_unregister(device_t dev); int sndstat_unregisterfile(char *str); -int sndstat_busy(void); #define SND_DECLARE_FILE(version) \ _SND_DECLARE_FILE(__LINE__, version) --- sys/dev/sound/pcm/sndstat.c.orig Thu Sep 15 11:25:01 2005 +++ sys/dev/sound/pcm/sndstat.c Thu Sep 15 11:31:07 2005 @@ -195,6 +195,42 @@ } int +sndstat_acquire(void) +{ + intrmask_t s; + + s = spltty(); + sx_xlock(&sndstat_lock); + if (sndstat_isopen) { + sx_unlock(&sndstat_lock); + splx(s); + return EBUSY; + } + sndstat_isopen = 1; + sx_unlock(&sndstat_lock); + splx(s); + return 0; +} + +int +sndstat_release(void) +{ + intrmask_t s; + + s = spltty(); + sx_xlock(&sndstat_lock); + if (!sndstat_isopen) { + sx_unlock(&sndstat_lock); + splx(s); + return EBADF; + } + sndstat_isopen = 0; + sx_unlock(&sndstat_lock); + splx(s); + return 0; +} + +int sndstat_register(device_t dev, char *str, sndstat_handler handler) { intrmask_t s; @@ -371,12 +407,6 @@ sx_xunlock(&sndstat_lock); sx_destroy(&sndstat_lock); return 0; -} - -int -sndstat_busy(void) -{ - return (sndstat_isopen); } static void --- sys/dev/sound/pcm/sound.c.orig Thu Sep 15 11:25:05 2005 +++ sys/dev/sound/pcm/sound.c Thu Sep 15 11:31:07 2005 @@ -758,24 +758,25 @@ struct snddev_channel *sce; struct pcm_channel *ch; + if (sndstat_acquire() != 0) { + device_printf(dev, "unregister: sndstat busy\n"); + return EBUSY; + } + snd_mtxlock(d->lock); if (d->inprog) { device_printf(dev, "unregister: operation in progress\n"); snd_mtxunlock(d->lock); + sndstat_release(); return EBUSY; } - if (sndstat_busy() != 0) { - device_printf(dev, "unregister: sndstat busy\n"); - snd_mtxunlock(d->lock); - return EBUSY; - } - SLIST_FOREACH(sce, &d->channels, link) { ch = sce->channel; if (ch->refcount > 0) { device_printf(dev, "unregister: channel %s busy (pid %d)\n", ch->name, ch->pid); snd_mtxunlock(d->lock); + sndstat_release(); return EBUSY; } } @@ -783,6 +784,7 @@ if (mixer_uninit(dev)) { device_printf(dev, "unregister: mixer busy\n"); snd_mtxunlock(d->lock); + sndstat_release(); return EBUSY; } @@ -807,9 +809,10 @@ chn_kill(d->fakechan); fkchan_kill(d->fakechan); - sndstat_unregister(dev); snd_mtxunlock(d->lock); snd_mtxfree(d->lock); + sndstat_unregister(dev); + sndstat_release(); return 0; }