--- sys/dev/sound/pcm/dsp.c.ORG Tue Nov 11 14:38:28 2003 +++ sys/dev/sound/pcm/dsp.c Fri Feb 27 12:13:13 2004 @@ -491,7 +491,12 @@ if (wrch && wrch->bufhard.dl) while (chn_wrfeed(wrch) == 0); */ - *arg_i = wrch? sndbuf_getfree(wrch->bufsoft) : 0; + if (wrch) { + CHN_LOCK(wrch); + *arg_i = sndbuf_getfree(wrch->bufsoft); + CHN_UNLOCK(wrch); + } else + *arg_i = 0; break; case AIOSSIZE: /* set the current blocksize */ @@ -518,10 +523,16 @@ { struct snd_size *p = (struct snd_size *)arg; - if (wrch) + if (wrch) { + CHN_LOCK(wrch); p->play_size = sndbuf_getblksz(wrch->bufsoft); - if (rdch) + CHN_UNLOCK(wrch); + } + if (rdch) { + CHN_LOCK(rdch); p->rec_size = sndbuf_getblksz(rdch->bufsoft); + CHN_UNLOCK(rdch); + } } break; @@ -548,10 +559,18 @@ { snd_chan_param *p = (snd_chan_param *)arg; + if (wrch) + CHN_LOCK(wrch); + if (rdch) + CHN_LOCK(rdch); p->play_rate = wrch? wrch->speed : 0; p->rec_rate = rdch? rdch->speed : 0; p->play_format = wrch? wrch->format : 0; p->rec_format = rdch? rdch->format : 0; + if (wrch) + CHN_UNLOCK(wrch); + if (rdch) + CHN_UNLOCK(rdch); } break; @@ -592,10 +611,16 @@ break; case AIOSTOP: - if (*arg_i == AIOSYNC_PLAY && wrch) + if (*arg_i == AIOSYNC_PLAY && wrch) { + CHN_LOCK(wrch); *arg_i = chn_abort(wrch); - else if (*arg_i == AIOSYNC_CAPTURE && rdch) + CHN_UNLOCK(wrch); + } + else if (*arg_i == AIOSYNC_CAPTURE && rdch) { + CHN_LOCK(rdch); *arg_i = chn_abort(rdch); + CHN_UNLOCK(rdch); + } else { printf("AIOSTOP: bad channel 0x%x\n", *arg_i); *arg_i = 0; @@ -613,7 +638,13 @@ case FIONREAD: /* get # bytes to read */ /* if (rdch && rdch->bufhard.dl) while (chn_rdfeed(rdch) == 0); -*/ *arg_i = rdch? sndbuf_getready(rdch->bufsoft) : 0; +*/ + if (rdch) { + CHN_LOCK(rdch); + *arg_i = sndbuf_getready(rdch->bufsoft); + CHN_UNLOCK(rdch); + } else + *arg_i = 0; break; case FIOASYNC: /*set/clear async i/o */ @@ -622,15 +653,19 @@ case SNDCTL_DSP_NONBLOCK: case FIONBIO: /* set/clear non-blocking i/o */ - if (rdch) + if (rdch) { + CHN_LOCK(rdch); rdch->flags &= ~CHN_F_NBIO; - if (wrch) - wrch->flags &= ~CHN_F_NBIO; - if (*arg_i) { - if (rdch) + if (*arg_i) rdch->flags |= CHN_F_NBIO; - if (wrch) + CHN_UNLOCK(rdch); + } + if (wrch) { + CHN_LOCK(wrch); + wrch->flags &= ~CHN_F_NBIO; + if (*arg_i) wrch->flags |= CHN_F_NBIO; + CHN_UNLOCK(wrch); } break; @@ -640,11 +675,15 @@ #define THE_REAL_SNDCTL_DSP_GETBLKSIZE _IOWR('P', 4, int) case THE_REAL_SNDCTL_DSP_GETBLKSIZE: case SNDCTL_DSP_GETBLKSIZE: - if (wrch) + if (wrch) { + CHN_LOCK(wrch); *arg_i = sndbuf_getblksz(wrch->bufsoft); - else if (rdch) + CHN_UNLOCK(wrch); + } else if (rdch) { + CHN_LOCK(rdch); *arg_i = sndbuf_getblksz(rdch->bufsoft); - else + CHN_UNLOCK(rdch); + } else *arg_i = 0; break ; @@ -664,10 +703,18 @@ case SNDCTL_DSP_RESET: DEB(printf("dsp reset\n")); - if (wrch) + if (wrch) { + CHN_LOCK(wrch); chn_abort(wrch); - if (rdch) + chn_resetbuf(wrch); + CHN_UNLOCK(wrch); + } + if (rdch) { + CHN_LOCK(rdch); chn_abort(rdch); + chn_resetbuf(rdch); + CHN_UNLOCK(rdch); + } break; case SNDCTL_DSP_SYNC: @@ -700,7 +747,16 @@ break; case SOUND_PCM_READ_RATE: - *arg_i = wrch? wrch->speed : rdch->speed; + if (wrch) { + CHN_LOCK(wrch); + *arg_i = wrch->speed; + CHN_UNLOCK(wrch); + } + if (rdch) { + CHN_LOCK(rdch); + *arg_i = rdch->speed; + CHN_UNLOCK(rdch); + } break; case SNDCTL_DSP_STEREO: @@ -742,16 +798,43 @@ } *arg_i = tmp; } else { - *arg_i = ((wrch? wrch->format : rdch->format) & AFMT_STEREO)? 2 : 1; + if (wrch) { + CHN_LOCK(wrch); + *arg_i = (wrch->format & AFMT_STEREO) ? 2 : 1; + CHN_UNLOCK(wrch); + } + if (rdch) { + CHN_LOCK(rdch); + *arg_i = (rdch->format & AFMT_STEREO) ? 2 : 1; + CHN_UNLOCK(rdch); + } } break; case SOUND_PCM_READ_CHANNELS: - *arg_i = ((wrch? wrch->format : rdch->format) & AFMT_STEREO)? 2 : 1; + if (wrch) { + CHN_LOCK(wrch); + *arg_i = (wrch->format & AFMT_STEREO) ? 2 : 1; + CHN_UNLOCK(wrch); + } + if (rdch) { + CHN_LOCK(rdch); + *arg_i = (rdch->format & AFMT_STEREO) ? 2 : 1; + CHN_UNLOCK(rdch); + } break; case SNDCTL_DSP_GETFMTS: /* returns a mask of supported fmts */ - *arg_i = wrch? chn_getformats(wrch) : chn_getformats(rdch); + if (wrch) { + CHN_LOCK(wrch); + *arg_i = chn_getformats(wrch); + CHN_UNLOCK(wrch); + } + if (rdch) { + CHN_LOCK(rdch); + *arg_i = chn_getformats(rdch); + CHN_UNLOCK(rdch); + } break ; case SNDCTL_DSP_SETFMT: /* sets _one_ format */ @@ -772,8 +855,18 @@ CHN_UNLOCK(rdch); } *arg_i = tmp; - } else - *arg_i = (wrch? wrch->format : rdch->format) & ~AFMT_STEREO; + } else { + if (wrch) { + CHN_LOCK(wrch); + *arg_i = wrch->format & ~AFMT_STEREO; + CHN_UNLOCK(wrch); + } + if (rdch) { + CHN_LOCK(rdch); + *arg_i = rdch->format & ~AFMT_STEREO; + CHN_UNLOCK(rdch); + } + } break; case SNDCTL_DSP_SETFRAGMENT: @@ -897,7 +990,16 @@ break; case SOUND_PCM_READ_BITS: - *arg_i = ((wrch? wrch->format : rdch->format) & AFMT_16BIT)? 16 : 8; + if (wrch) { + CHN_LOCK(wrch); + *arg_i = (wrch->format & AFMT_16BIT) ? 16 : 8; + CHN_UNLOCK(wrch); + } + if (rdch) { + CHN_LOCK(rdch); + *arg_i = (rdch->format & AFMT_16BIT) ? 16 : 8; + CHN_UNLOCK(rdch); + } break; case SNDCTL_DSP_SETTRIGGER: @@ -923,10 +1025,18 @@ case SNDCTL_DSP_GETTRIGGER: *arg_i = 0; - if (wrch && wrch->flags & CHN_F_TRIGGERED) - *arg_i |= PCM_ENABLE_OUTPUT; - if (rdch && rdch->flags & CHN_F_TRIGGERED) - *arg_i |= PCM_ENABLE_INPUT; + if (wrch) { + CHN_LOCK(wrch); + if (wrch->flags & CHN_F_TRIGGERED) + *arg_i |= PCM_ENABLE_OUTPUT; + CHN_UNLOCK(wrch); + } + if (rdch) { + CHN_LOCK(rdch); + if (rdch->flags & CHN_F_TRIGGERED) + *arg_i |= PCM_ENABLE_INPUT; + CHN_UNLOCK(rdch); + } break; case SNDCTL_DSP_GETODELAY: