From 6ad1e4d99aba346440e984a232a312ea49561e7d Mon Sep 17 00:00:00 2001 From: NanoTech Date: Sun, 12 Oct 2014 16:23:33 -0600 Subject: Revert "Main: run the OS X native event loop" This reverts commit f0be48ff90503d9ffa5b295fd4454eec753950ee (except for the NEWS entry). If libdispatch (GCD) is used before forking, it can't safely be used again after forking. --- src/Main.cxx | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/Main.cxx') diff --git a/src/Main.cxx b/src/Main.cxx index d17590e44..417e055d6 100644 --- a/src/Main.cxx +++ b/src/Main.cxx @@ -401,8 +401,6 @@ int main(int argc, char *argv[]) { #ifdef WIN32 return win32_main(argc, argv); -#elif __APPLE__ - return osx_main(argc, argv); #else return mpd_main(argc, argv); #endif -- cgit v1.2.3 From d42c0f1dc5063d50a62817b63a1c2a4507c46071 Mon Sep 17 00:00:00 2001 From: NanoTech Date: Sun, 12 Oct 2014 16:29:43 -0600 Subject: Main: run the OS X native event loop after forking --- src/Main.cxx | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/Main.cxx') diff --git a/src/Main.cxx b/src/Main.cxx index 417e055d6..2719c05e0 100644 --- a/src/Main.cxx +++ b/src/Main.cxx @@ -114,6 +114,10 @@ #include #endif +#ifdef __APPLE__ +#include +#endif + #include static constexpr unsigned DEFAULT_BUFFER_SIZE = 4096; @@ -408,6 +412,8 @@ int main(int argc, char *argv[]) #endif +static int mpd_main_after_fork(struct options); + #ifdef ANDROID static inline #endif @@ -511,6 +517,27 @@ int mpd_main(int argc, char *argv[]) daemonize_begin(options.daemon); #endif +#ifdef __APPLE__ + /* Runs the OS X native event loop in the main thread, and runs + the rest of mpd_main on a new thread. This lets CoreAudio receive + route change notifications (e.g. plugging or unplugging headphones). + All hardware output on OS X ultimately uses CoreAudio internally. + This must be run after forking; if dispatch is called before forking, + the child process will have a broken internal dispatch state. */ + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ + exit(mpd_main_after_fork(options)); + }); + dispatch_main(); + return EXIT_FAILURE; // unreachable, because dispatch_main never returns +#else + return mpd_main_after_fork(options); +#endif +} + +static int mpd_main_after_fork(struct options options) +{ + Error error; + GlobalEvents::Initialize(*instance->event_loop); GlobalEvents::Register(GlobalEvents::IDLE, idle_event_emitted); #ifdef WIN32 -- cgit v1.2.3