+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
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);
/* 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);
}
}
/* 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);
}
}
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);
}
}
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);
}
}
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;
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;
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;
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;
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;
// 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;
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;
/* 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;
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);
/* 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));