]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - alsa_write.c
alsa: Avoid busy loop with dmix.
[paraslash.git] / alsa_write.c
index 047e88f2200a45f2518c7f1508874108e26a6bce..b89c8c31c8007ec6267ecac96acec6ca0d1ad1ce 100644 (file)
@@ -248,12 +248,23 @@ again:
                wn->min_iqs = pad->bytes_per_frame;
                goto again;
        }
-       if (pad->poll_fd >= 0 && !FD_ISSET(pad->poll_fd, &s->rfds))
+       if (pad->poll_fd < 0 || !FD_ISSET(pad->poll_fd, &s->rfds))
                return;
        frames = bytes / pad->bytes_per_frame;
        frames = snd_pcm_writei(pad->handle, data, frames);
-       if (frames == 0 || frames == -EAGAIN)
+       if (frames == 0 || frames == -EAGAIN) {
+               /*
+                * The alsa poll fd was ready for IO but we failed to write to
+                * the alsa handle. This means another event is pending. We
+                * don't care about that but we have to dispatch the event in
+                * order to avoid a busy loop. So we simply read from the poll
+                * fd.
+                */
+               char buf[100];
+               if (read(pad->poll_fd, buf, 100))
+                       do_nothing;
                return;
+       }
        if (frames > 0) {
                btr_consume(btrn, frames * pad->bytes_per_frame);
                goto again;