From: Pierre Habouzit Date: Fri, 11 Jan 2008 23:55:43 +0000 (+0100) Subject: Have an event loop thread. X-Git-Url: http://git.madism.org/?a=commitdiff_plain;h=f8d1899d44b259a0920a52bd7290f15e39fd0d47;p=apps%2Fmadmutt.git Have an event loop thread. Signed-off-by: Pierre Habouzit --- diff --git a/lib-sys/evtloop.c b/lib-sys/evtloop.c index 11546b2..4b2f0d8 100644 --- a/lib-sys/evtloop.c +++ b/lib-sys/evtloop.c @@ -306,3 +306,19 @@ int el_dispatch(int timeout) return 0; } + +void el_initialize(void) +{ + gnutls_global_init(); + epollfd = epoll_create(1024); + if (epollfd < 0) { + mutt_error("epoll_create"); + mutt_exit(EXIT_FAILURE); + } +} + +void el_shutdown(void) +{ + close(epollfd); + gnutls_global_deinit(); +} diff --git a/lib-sys/evtloop.h b/lib-sys/evtloop.h index 8b465f5..c96f0c2 100644 --- a/lib-sys/evtloop.h +++ b/lib-sys/evtloop.h @@ -23,6 +23,7 @@ #include #include +#include typedef enum el_state { EL_LLP_INIT, @@ -98,5 +99,7 @@ static inline job_t *el_job_start(const machine_t *m, void *cfg) { } int el_dispatch(int timeout); +void el_initialize(void); +void el_shutdown(void); #endif diff --git a/main.c b/main.c index 2d52aa9..74f95be 100644 --- a/main.c +++ b/main.c @@ -18,9 +18,11 @@ #include #include +#include #include #include +#include #include #include #include @@ -174,6 +176,14 @@ 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] = ""; @@ -188,6 +198,7 @@ int main (int argc, char **argv) int version = 0; int i; int explicit_folder = 0; + pthread_t pt; /* initialize random number for tmp file creation */ srand48((unsigned int) time (NULL)); @@ -303,8 +314,10 @@ int main (int argc, char **argv) } /* set defaults and read init files */ + el_initialize(); mutt_init (flags & M_NOSYSRC, commands); string_list_wipe(&commands); + pthread_create(&pt, NULL, &evtloop, NULL); if (!option(OPTNOCURSES)) { ui_layout_init(); @@ -490,6 +503,7 @@ int main (int argc, char **argv) NULL)) || !explicit_folder) { mutt_index_menu (); + if (option (OPTXTERMSETTITLES)) printf("\033]2;%s\007", NONULL(XtermLeave)); if (Context) @@ -498,7 +512,10 @@ int main (int argc, char **argv) mutt_endwin (Errorbuf); } + pthread_cancel(pt); + pthread_join(pt, NULL); luaM_shutdown(); mutt_sasl_shutdown(); + el_shutdown(); exit (0); }