From: Pierre Habouzit Date: Sat, 12 Jan 2008 13:47:29 +0000 (+0100) Subject: Move the event loop to evtloop.c, and wake up sleeping jobs every 10 seconds. X-Git-Url: http://git.madism.org/?a=commitdiff_plain;h=20e55d4252ca2db1fc2b1099acf8393c22903575;p=apps%2Fmadmutt.git Move the event loop to evtloop.c, and wake up sleeping jobs every 10 seconds. Signed-off-by: Pierre Habouzit --- diff --git a/lib-sys/evtloop.c b/lib-sys/evtloop.c index 3ecfb57..a28c9b8 100644 --- a/lib-sys/evtloop.c +++ b/lib-sys/evtloop.c @@ -17,6 +17,7 @@ * Copyright © 2006 Pierre Habouzit */ +#include #include #include #ifndef EPOLLRDHUP @@ -309,6 +310,7 @@ int el_dispatch(int timeout) int event = events[count].events; int evt = 0; + gettimeofday(&w->mru, NULL); switch (w->state) { case EL_LLP_INIT: w->llp(w); @@ -337,6 +339,29 @@ int el_dispatch(int timeout) return 0; } +void *el_loop(void *data) +{ + time_t sec = time(NULL); + + for (;;) { + struct timeval now; + + el_dispatch(100); + pthread_testcancel(); + + gettimeofday(&now, NULL); + if (sec >= now.tv_sec) + continue; + sec = now.tv_sec; + now.tv_sec -= 10; + for (int i = jobs.len - 1; i >= 0; --i) { + job_t *w = jobs.arr[i]; + if (timercmp(&now, &w->mru, >)) + IGNORE(w->m->on_event(w, EL_EVT_WAKEUP)); + } + } +} + void el_initialize(void) { gnutls_global_init(); diff --git a/lib-sys/evtloop.h b/lib-sys/evtloop.h index 73c9ec5..0865039 100644 --- a/lib-sys/evtloop.h +++ b/lib-sys/evtloop.h @@ -65,6 +65,7 @@ typedef struct job_t { el_mode mode : 3; el_mode emode : 3; + struct timeval mru; int (*llp)(struct job_t *); const struct machine_t *m; void *ptr; @@ -96,6 +97,8 @@ __must_check__ ssize_t el_job_write(job_t *w, buffer_t *buf); int el_dispatch(int timeout); +void *el_loop(void *); + void el_initialize(void); void el_shutdown(void); diff --git a/main.c b/main.c index 74f95be..af2141e 100644 --- a/main.c +++ b/main.c @@ -176,14 +176,6 @@ static void mutt_nocurses_error (const char *fmt, ...) fputc('\n', stderr); } -static void *evtloop(void *data) -{ - for (;;) { - el_dispatch(100); - pthread_testcancel(); - } -} - int main (int argc, char **argv) { char folder[_POSIX_PATH_MAX] = ""; @@ -317,7 +309,7 @@ int main (int argc, char **argv) el_initialize(); mutt_init (flags & M_NOSYSRC, commands); string_list_wipe(&commands); - pthread_create(&pt, NULL, &evtloop, NULL); + pthread_create(&pt, NULL, &el_loop, NULL); if (!option(OPTNOCURSES)) { ui_layout_init();