]> git.alsa-project.org Git - tinycompress.git/commitdiff
compress: do not poll if enough space to write remaining data
authorRichard Fitzgerald <rf@opensource.wolfsonmicro.com>
Wed, 5 Jun 2013 12:11:44 +0000 (13:11 +0100)
committerVinod Koul <vinod.koul@intel.com>
Fri, 7 Jun 2013 00:29:51 +0000 (05:59 +0530)
Changes the poll logic in compress_write() to prevent
it polling if there is enough available space to write
all remaining data. Previously the logic always polled for
an entire fragment to become available before starting the
first write.

This change allows short writes of < frag_size, which is likely
at the end of a stream.

Signed-off-by: Richard Fitzgerald <rf@opensource.wolfsonmicro.com>
Signed-off-by: Vinod Koul <vinod.koul@intel.com>
compress.c

index 373de8578ebf7dc1dd92ba443debbad4df171bea..bb68fa68fba3f59f1703816e243e59c2ad53f507 100644 (file)
@@ -368,12 +368,10 @@ int compress_write(struct compress *compress, const void *buf, unsigned int size
                if (ioctl(compress->fd, SNDRV_COMPRESS_AVAIL, &avail))
                        return oops(compress, errno, "cannot get avail");
 
-               if ( (avail.avail < frag_size)
-                       || ((to_write != 0) && (avail.avail < size)) ) {
-                       /* not enough space for one fragment, or we have done
-                        * a short write and there isn't enough space for all
-                        * the remaining data
-                        */
+               /* We can write if we have at least one fragment available
+                * or there is enough space for all remaining data
+                */
+               if ((avail.avail < frag_size) && (avail.avail < size)) {
                        ret = poll(&fds, 1, compress->max_poll_wait_ms);
                        /* A pause will cause -EBADFD or zero.
                         * This is not an error, just stop writing */