From 1405e5c066253957c5e795184b1ae528734dcbed Mon Sep 17 00:00:00 2001 From: Christof Ressi Date: Wed, 12 Aug 2020 23:33:47 +0200 Subject: [PATCH] sys_main: wrap whole event loop code inside #ifdef PD_EVENTLOOP --- src/s_main.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/s_main.c b/src/s_main.c index d6bf4d572a..4552012224 100644 --- a/src/s_main.c +++ b/src/s_main.c @@ -12,7 +12,9 @@ #include #include #include +#ifdef PD_EVENTLOOP #include +#endif #ifdef HAVE_UNISTD_H #include @@ -320,7 +322,17 @@ static void sys_fakefromgui(void) static void sys_afterargparse(void); static void sys_printusage(void); static int sys_run(void); -static void *sys_runthread(void *); + +#ifdef PD_EVENTLOOP +static void *sys_runthread(void *x) +{ + int *ret = (int *)x; + *ret = sys_run(); + /* fprintf(stderr, "quit event loop\n"); */ + sys_eventloop_quit(); + return 0; +} +#endif /* this is called from main() in s_entry.c */ int sys_main(int argc, char **argv) @@ -391,42 +403,30 @@ int sys_main(int argc, char **argv) clock_new(0, (t_method)sys_fakefromgui)), 0); else if (sys_startgui(sys_libdir->s_name)) /* start the gui */ return (1); +#ifdef PD_EVENTLOOP if (sys_eventloop && !sys_batch) { pthread_t thread; int ret, err; - /* First setup event loop. This is necessary in case sys_run() - returns before we get a chance to call sys_eventloop_run(). */ - #ifdef PD_EVENTLOOP + /* First setup event loop. This is necessary in case sys_run() + returns before we get a chance to call sys_eventloop_run(). */ /* fprintf(stderr, "start event loop\n"); */ sys_eventloop_setup(); - #endif if ((err = pthread_create(&thread, 0, sys_runthread, &ret))) { fprintf(stderr, "pthread_create() failed with %d\n", err); return (1); } - /* run event loop in main thread until we receive a quit event */ - #ifdef PD_EVENTLOOP + /* run event loop in main thread until we receive a quit event */ sys_eventloop_run(); /* fprintf(stderr, "event loop finished\n"); */ - #endif + pthread_join(thread, 0); return ret; } else - return sys_run(); -} - -static void *sys_runthread(void *x) -{ - int *ret = (int *)x; - *ret = sys_run(); -#ifdef PD_EVENTLOOP - /* fprintf(stderr, "quit event loop\n"); */ - sys_eventloop_quit(); #endif - return 0; + return sys_run(); } static int sys_run(void)