Skip to content

Commit

Permalink
[ALSA] Fix PCM write blocking
Browse files Browse the repository at this point in the history
The snd_pcm_lib_write1() may block in some weird condition:
  - the stream isn't started
  - avail_min is big (e.g. period size)
  - partial write up to buffer_size - avail_min
The patch fixes this invalid blocking problem.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
  • Loading branch information
Takashi Iwai authored and Jaroslav Kysela committed Jan 31, 2008
1 parent 8ace4f3 commit fa5717f
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions sound/core/pcm_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1655,8 +1655,11 @@ static snd_pcm_sframes_t snd_pcm_lib_write1(struct snd_pcm_substream *substream,
if (runtime->sleep_min == 0 && runtime->status->state == SNDRV_PCM_STATE_RUNNING)
snd_pcm_update_hw_ptr(substream);
avail = snd_pcm_playback_avail(runtime);
if (((avail < runtime->control->avail_min && size > avail) ||
(size >= runtime->xfer_align && avail < runtime->xfer_align))) {
if (!avail ||
(snd_pcm_running(substream) &&
((avail < runtime->control->avail_min && size > avail) ||
(size >= runtime->xfer_align &&
avail < runtime->xfer_align)))) {
wait_queue_t wait;
enum { READY, SIGNALED, ERROR, SUSPENDED, EXPIRED, DROPPED } state;
long tout;
Expand Down

0 comments on commit fa5717f

Please sign in to comment.