diff --git a/ChangeLog b/ChangeLog index 50935a78..bf2f66c3 100644 --- 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 diff --git a/src/conky.c b/src/conky.c index bb6997a5..04724512 100644 --- a/src/conky.c +++ b/src/conky.c @@ -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); } } diff --git a/src/moc.c b/src/moc.c index b9d18378..f15f2206 100644 --- 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); } } diff --git a/src/mpd.c b/src/mpd.c index 150bb1cf..1f8c73a4 100644 --- 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; diff --git a/src/timed_thread.c b/src/timed_thread.c index 8226d465..bdcf1744 100644 --- a/src/timed_thread.c +++ b/src/timed_thread.c @@ -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); diff --git a/src/timed_thread.h b/src/timed_thread.h index 9ff26c1d..533e11f9 100644 --- a/src/timed_thread.h +++ b/src/timed_thread.h @@ -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));