]> git.alsa-project.org Git - tinycompress.git/commitdiff
compress: Remove hardcoded limit on length of poll() wait
authorRichard Fitzgerald <rf@opensource.wolfsonmicro.com>
Fri, 22 Feb 2013 16:03:25 +0000 (16:03 +0000)
committerVinod Koul <vinod.koul@intel.com>
Fri, 22 Feb 2013 18:08:12 +0000 (23:38 +0530)
For best power-saving we want to sleep on poll() for as long as
possible, we don't want to wake unnecessarily for arbitrary time
limits. Adds function compress_set_max_poll_wait() so that
client can configure the poll() timeout.

Signed-off-by: Vinod Koul <vinod.koul@intel.com>
compress.c
include/tinycompress/tinycompress.h

index 801f0551a06ef4dd6dde1fcdf8b614adbceeabff..478652af064a81e07b1727a78ed95527e3bc2a0b 100644 (file)
 
 #define COMPR_ERR_MAX 128
 
+/* Default maximum time we will wait in a poll() - 20 seconds */
+#define DEFAULT_MAX_POLL_WAIT_MS    20000
+
 struct compress {
        int fd;
        unsigned int flags;
        char error[COMPR_ERR_MAX];
        struct compr_config *config;
        int running;
+       int max_poll_wait_ms;
 };
 
 static int oops(struct compress *compress, int e, const char *fmt, ...)
@@ -217,6 +221,8 @@ struct compress *compress_open(unsigned int card, unsigned int device,
 
        snprintf(fn, sizeof(fn), "/dev/snd/comprC%uD%u", card, device);
 
+       compress->max_poll_wait_ms = DEFAULT_MAX_POLL_WAIT_MS;
+
        compress->flags = flags;
        if (!((flags & COMPRESS_OUT) || (flags & COMPRESS_IN))) {
                oops(&bad_compress, -EINVAL, "can't deduce device direction from given flags");
@@ -331,9 +337,9 @@ int compress_write(struct compress *compress, const void *buf, unsigned int size
                        return oops(compress, errno, "cannot get avail");
 
                /* we will write only when avail > fragment size */
-               if (avail.avail < compress->config->fragment_size) {
-                       /* nothing to write so wait for 10secs */
-                       ret = poll(&fds, 1, 1000000);
+               if (avail.avail < compress->config.fragment_size) {
+                       /* nothing to write so wait */
+                       ret = poll(&fds, 1, compress->max_poll_wait_ms);
                        if (ret < 0)
                                return oops(compress, errno, "poll error");
                        if (ret == 0)
@@ -441,3 +447,8 @@ bool is_codec_supported(unsigned int card, unsigned int device,
        return ret;
 }
 
+void compress_set_max_poll_wait(struct compress *compress, int milliseconds)
+{
+       compress->max_poll_wait_ms = milliseconds;
+}
+
index 49c0ff2ff90a07586bceefbbad05d1a2923e3e7f..982ff6b701bbbdeb694137593e2a803ec98126fe 100644 (file)
@@ -190,6 +190,16 @@ int compress_drain(struct compress *compress);
 bool is_codec_supported(unsigned int card, unsigned int device,
               unsigned int flags, struct snd_codec *codec);
 
+/*
+ * compress_set_max_poll_wait: set the maximum time tinycompress
+ * will wait for driver to signal a poll(). Interval is in
+ * milliseconds.
+ * Pass interval of -1 to disable timeout and make poll() wait
+ * until driver signals.
+ * If this function is not used the timeout defaults to 20 seconds.
+ */
+void compress_set_max_poll_wait(struct compress *compress, int milliseconds);
+
 int is_compress_running(struct compress *compress);
 
 int is_compress_ready(struct compress *compress);