]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
alsa: Avoid busy loop.
authorAndre Noll <maan@systemlinux.org>
Sun, 24 Jul 2011 20:18:42 +0000 (22:18 +0200)
committerAndre Noll <maan@systemlinux.org>
Sun, 24 Jul 2011 20:19:15 +0000 (22:19 +0200)
It is possible that snd_pcm_writei() returns zero rather than -EAGAIN
in case nothing was written because the alsa buffer was already full.

Currently we try again, and eventually succeed. However, this is
ugly, burns CPU cycles and might even lead to an endless loop for
misconfigured alsa devices. So simply return from alsa_post_select()
if snd_pcm_writei() returned zero.

alsa_write.c

index 1c168e7b4b037f8e8853681e02254879f0912640..6850221a83d861e04cfcd8254d3114f837013a2e 100644 (file)
@@ -253,7 +253,9 @@ again:
        }
        frames = bytes / pad->bytes_per_frame;
        frames = snd_pcm_writei(pad->handle, data, frames);
        }
        frames = bytes / pad->bytes_per_frame;
        frames = snd_pcm_writei(pad->handle, data, frames);
-       if (frames >= 0) {
+       if (frames == 0 || frames == -EAGAIN)
+               return;
+       if (frames > 0) {
                btr_consume(btrn, frames * pad->bytes_per_frame);
                goto again;
        }
                btr_consume(btrn, frames * pad->bytes_per_frame);
                goto again;
        }
@@ -262,8 +264,6 @@ again:
                snd_pcm_prepare(pad->handle);
                return;
        }
                snd_pcm_prepare(pad->handle);
                return;
        }
-       if (frames == -EAGAIN)
-               return;
        PARA_WARNING_LOG("%s\n", snd_strerror(-frames));
        ret = -E_ALSA_WRITE;
 err:
        PARA_WARNING_LOG("%s\n", snd_strerror(-frames));
        ret = -E_ALSA_WRITE;
 err: