Skip to content

Commit

Permalink
sys_main: wrap whole event loop code inside #ifdef PD_EVENTLOOP
Browse files Browse the repository at this point in the history
  • Loading branch information
Spacechild1 committed Aug 30, 2020
1 parent a84b346 commit 1405e5c
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions src/s_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#ifdef PD_EVENTLOOP
#include <pthread.h>
#endif

#ifdef HAVE_UNISTD_H
#include <unistd.h>
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 1405e5c

Please sign in to comment.