From: Andre Noll Date: Sun, 24 Jul 2011 20:18:42 +0000 (+0200) Subject: alsa: Avoid busy loop. X-Git-Tag: v0.4.8~26 X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=commitdiff_plain;h=4773c4fe3f00eaad35850cb0424cdece8e2a5a91 alsa: Avoid busy loop. 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. --- diff --git a/alsa_write.c b/alsa_write.c index 1c168e7b..6850221a 100644 --- a/alsa_write.c +++ b/alsa_write.c @@ -253,7 +253,9 @@ again: } 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; } @@ -262,8 +264,6 @@ again: snd_pcm_prepare(pad->handle); return; } - if (frames == -EAGAIN) - return; PARA_WARNING_LOG("%s\n", snd_strerror(-frames)); ret = -E_ALSA_WRITE; err: