diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2011-09-15 22:13:48 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-09-15 22:13:48 -0700 |
commit | c455ea4f122d21c91fcf4c36c3f0c08535ba3ce8 (patch) | |
tree | 4eef0a4e28bde9715e06389d229facfb3039b01e /sound/core/pcm_lib.c | |
parent | a7f934d4f16144cb9521b62e9b8c9ac0118097da (diff) | |
parent | 763437a9e7737535b2fc72175ad4974048769be6 (diff) |
Merge branch 'for-linus' of git://github.com/tiwai/sound
* 'for-linus' of git://github.com/tiwai/sound:
ALSA: pcm - fix race condition in wait_for_avail()
ALSA: HDA: Cirrus - fix "Surround Speaker" volume control name
ALSA: hda - Terminate the recursive connection search properly
ASoC: Fix trivial build regression in Kirkwood I2S
ASoC: Blackfin: bf5xx-ad193x: Fix codec device name
ASoC: Fix reporting of partial jack updates
ASoC: imx: Fix build warning of unused 'card' variable
ASoC: Fix register cache sync register_writable WARN_ONs
ASoC: snd_soc_codec_{readable,writable}_register change default to true
ASoC: soc-dapm: Fix parameter comment for snd_soc_dapm_free
MAINTAINERS: Add some missed Wolfson files
ASoC: MPC5200: replace of_device with platform_device
Diffstat (limited to 'sound/core/pcm_lib.c')
-rw-r--r-- | sound/core/pcm_lib.c | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c index 86d0caf91b3..62e90b862a0 100644 --- a/sound/core/pcm_lib.c +++ b/sound/core/pcm_lib.c @@ -1761,6 +1761,10 @@ static int wait_for_avail(struct snd_pcm_substream *substream, snd_pcm_uframes_t avail = 0; long wait_time, tout; + init_waitqueue_entry(&wait, current); + set_current_state(TASK_INTERRUPTIBLE); + add_wait_queue(&runtime->tsleep, &wait); + if (runtime->no_period_wakeup) wait_time = MAX_SCHEDULE_TIMEOUT; else { @@ -1771,16 +1775,32 @@ static int wait_for_avail(struct snd_pcm_substream *substream, } wait_time = msecs_to_jiffies(wait_time * 1000); } - init_waitqueue_entry(&wait, current); - add_wait_queue(&runtime->tsleep, &wait); + for (;;) { if (signal_pending(current)) { err = -ERESTARTSYS; break; } + + /* + * We need to check if space became available already + * (and thus the wakeup happened already) first to close + * the race of space already having become available. + * This check must happen after been added to the waitqueue + * and having current state be INTERRUPTIBLE. + */ + if (is_playback) + avail = snd_pcm_playback_avail(runtime); + else + avail = snd_pcm_capture_avail(runtime); + if (avail >= runtime->twake) + break; snd_pcm_stream_unlock_irq(substream); - tout = schedule_timeout_interruptible(wait_time); + + tout = schedule_timeout(wait_time); + snd_pcm_stream_lock_irq(substream); + set_current_state(TASK_INTERRUPTIBLE); switch (runtime->status->state) { case SNDRV_PCM_STATE_SUSPENDED: err = -ESTRPIPE; @@ -1806,14 +1826,9 @@ static int wait_for_avail(struct snd_pcm_substream *substream, err = -EIO; break; } - if (is_playback) - avail = snd_pcm_playback_avail(runtime); - else - avail = snd_pcm_capture_avail(runtime); - if (avail >= runtime->twake) - break; } _endloop: + set_current_state(TASK_RUNNING); remove_wait_queue(&runtime->tsleep, &wait); *availp = avail; return err; |