Add an option to timed_thread_test() to not wait for the interval period (so that...
authorBrenden Matthews <brenden@rty.ca>
Tue, 9 Dec 2008 08:37:59 +0000 (01:37 -0700)
committerBrenden Matthews <brenden@rty.ca>
Tue, 9 Dec 2008 08:37:59 +0000 (01:37 -0700)
ChangeLog
src/conky.c
src/moc.c
src/mpd.c
src/timed_thread.c
src/timed_thread.h

index 50935a7..bf2f66c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2008-12-09
+       * Add an option to timed_thread_test() to not wait for the interval period
+       (so that IMAP IDLE works better)
+
 2008-12-08
        * Fix runtime debugging macros again
        * Big hddtemp rewrite
index bb6997a..0472451 100644 (file)
@@ -1851,7 +1851,7 @@ void *imap_thread(void *arg)
                                        FD_SET(sockfd, &fdset);
                                        FD_SET(threadfd, &fdset);
                                        res = select(MAX(sockfd + 1, threadfd + 1), &fdset, NULL, NULL, NULL);
-                                       if (timed_thread_test(mail->p_timed_thread) || (res == -1 && errno == EINTR) || FD_ISSET(threadfd, &fdset)) {
+                                       if (timed_thread_test(mail->p_timed_thread, 1) || (res == -1 && errno == EINTR) || FD_ISSET(threadfd, &fdset)) {
                                                if ((fstat(sockfd, &stat_buf) == 0) && S_ISSOCK(stat_buf.st_mode)) {
                                                        /* if a valid socket, close it */
                                                        close(sockfd);
@@ -1975,7 +1975,7 @@ void *imap_thread(void *arg)
                        /* if a valid socket, close it */
                        close(sockfd);
                }
-               if (timed_thread_test(mail->p_timed_thread)) {
+               if (timed_thread_test(mail->p_timed_thread, 0)) {
                        timed_thread_exit(mail->p_timed_thread);
                }
        }
@@ -2148,7 +2148,7 @@ void *pop3_thread(void *arg)
                        /* if a valid socket, close it */
                        close(sockfd);
                }
-               if (timed_thread_test(mail->p_timed_thread)) {
+               if (timed_thread_test(mail->p_timed_thread, 0)) {
                        timed_thread_exit(mail->p_timed_thread);
                }
        }
@@ -2188,7 +2188,7 @@ void *threaded_exec(void *arg)
                        p2++;
                }
                timed_thread_unlock(obj->data.texeci.p_timed_thread);
-               if (timed_thread_test(obj->data.texeci.p_timed_thread)) {
+               if (timed_thread_test(obj->data.texeci.p_timed_thread, 0)) {
                        timed_thread_exit(obj->data.texeci.p_timed_thread);
                }
        }
index b9d1837..f15f220 100644 (file)
--- a/src/moc.c
+++ b/src/moc.c
@@ -103,7 +103,7 @@ void *update_moc(void *arg)
                timed_thread_lock(moc->timed_thread);
                update_infos(moc);
                timed_thread_unlock(moc->timed_thread);
-               if (timed_thread_test(moc->timed_thread)) {
+               if (timed_thread_test(moc->timed_thread, 0)) {
                        timed_thread_exit(moc->timed_thread);
                }
        }
index 150bb1c..1f8c73a 100644 (file)
--- a/src/mpd.c
+++ b/src/mpd.c
@@ -155,7 +155,7 @@ void *update_mpd(void *arg)
                        strncpy(mpd->status, "MPD not responding",
                                text_buffer_size - 1);
                        timed_thread_unlock(mpd->timed_thread);
-                       if (timed_thread_test(mpd->timed_thread)) {
+                       if (timed_thread_test(mpd->timed_thread, 0)) {
                                timed_thread_exit(mpd->timed_thread);
                        }
                        continue;
@@ -171,7 +171,7 @@ void *update_mpd(void *arg)
                        strncpy(mpd->status, "MPD not responding",
                                text_buffer_size - 1);
                        timed_thread_unlock(mpd->timed_thread);
-                       if (timed_thread_test(mpd->timed_thread)) {
+                       if (timed_thread_test(mpd->timed_thread, 0)) {
                                timed_thread_exit(mpd->timed_thread);
                        }
                        continue;
@@ -182,7 +182,7 @@ void *update_mpd(void *arg)
                        mpd_closeConnection(mpd->conn);
                        mpd->conn = 0;
                        timed_thread_unlock(mpd->timed_thread);
-                       if (timed_thread_test(mpd->timed_thread)) {
+                       if (timed_thread_test(mpd->timed_thread, 0)) {
                                timed_thread_exit(mpd->timed_thread);
                        }
                        continue;
@@ -236,7 +236,7 @@ void *update_mpd(void *arg)
                        mpd_closeConnection(mpd->conn);
                        mpd->conn = 0;
                        timed_thread_unlock(mpd->timed_thread);
-                       if (timed_thread_test(mpd->timed_thread)) {
+                       if (timed_thread_test(mpd->timed_thread, 0)) {
                                timed_thread_exit(mpd->timed_thread);
                        }
                        continue;
@@ -302,7 +302,7 @@ void *update_mpd(void *arg)
                        mpd_closeConnection(mpd->conn);
                        mpd->conn = 0;
                        timed_thread_unlock(mpd->timed_thread);
-                       if (timed_thread_test(mpd->timed_thread)) {
+                       if (timed_thread_test(mpd->timed_thread, 0)) {
                                timed_thread_exit(mpd->timed_thread);
                        }
                        continue;
@@ -313,7 +313,7 @@ void *update_mpd(void *arg)
                        // fprintf(stderr, "%s\n", mpd->conn->errorStr);
                        mpd_closeConnection(mpd->conn);
                        mpd->conn = 0;
-                       if (timed_thread_test(mpd->timed_thread)) {
+                       if (timed_thread_test(mpd->timed_thread, 0)) {
                                timed_thread_exit(mpd->timed_thread);
                        }
                        continue;
@@ -324,7 +324,7 @@ void *update_mpd(void *arg)
                        mpd_closeConnection(mpd->conn);
                        mpd->conn = 0;
                } */
-               if (timed_thread_test(mpd->timed_thread)) {
+               if (timed_thread_test(mpd->timed_thread, 0)) {
                        timed_thread_exit(mpd->timed_thread);
                }
                continue;
index 8226d46..bdcf174 100644 (file)
@@ -197,7 +197,7 @@ int timed_thread_unlock(timed_thread *p_timed_thread)
 /* thread waits interval_usecs for runnable_cond to be signaled.
  * returns 1 if signaled, -1 on error, and 0 otherwise.
  * caller should call timed_thread_exit() on any non-zero return value. */
-int timed_thread_test(timed_thread *p_timed_thread)
+int timed_thread_test(timed_thread *p_timed_thread, int override_wait_time)
 {
        struct timespec now_time;
        int rc;
@@ -211,6 +211,10 @@ int timed_thread_test(timed_thread *p_timed_thread)
                return -1;
        }
 
+       if (override_wait_time && now(&p_timed_thread->wait_time)) {
+               return -1;
+       }
+
        /* release mutex and wait until future time for runnable_cond to signal */
        rc = pthread_cond_timedwait(&p_timed_thread->runnable_cond,
                        &p_timed_thread->runnable_mutex, &p_timed_thread->wait_time);
index 9ff26c1..533e11f 100644 (file)
@@ -47,10 +47,9 @@ int timed_thread_lock(timed_thread *p_timed_thread);
 /* unlock a timed thread after critical section activity */
 int timed_thread_unlock(timed_thread *p_timed_thread);
 
-/* waits required interval for termination signal
- * returns 1 if received,
- * 0 otherwise */
-int timed_thread_test(timed_thread *p_timed_thread);
+/* waits required interval (unless override_wait_time is non-zero) for
+ * termination signal returns 1 if received, 0 otherwise. */
+int timed_thread_test(timed_thread *p_timed_thread, int override_wait_time);
 
 /* exit a timed thread */
 void timed_thread_exit(timed_thread *p_timed_thread) __attribute__((noreturn));