diff --git a/hw/xquartz/mach-startup/bundle-main.c b/hw/xquartz/mach-startup/bundle-main.c index d55d1edc7..6a6c01c3b 100644 --- a/hw/xquartz/mach-startup/bundle-main.c +++ b/hw/xquartz/mach-startup/bundle-main.c @@ -40,10 +40,15 @@ #include #include #include -#include #include #include +#ifdef HAVE_LIBDISPATCH +#include +#else +#include +#endif + #include #include @@ -94,6 +99,7 @@ int server_main(int argc, char **argv, char **envp); static int execute(const char *command); static char *command_from_prefs(const char *key, const char *default_value); +#ifndef HAVE_LIBDISPATCH /*** Pthread Magics ***/ static pthread_t create_thread(void *(*func)(void *), void *arg) { pthread_attr_t attr; @@ -107,6 +113,7 @@ static pthread_t create_thread(void *(*func)(void *), void *arg) { return tid; } +#endif /*** Mach-O IPC Stuffs ***/ @@ -199,8 +206,13 @@ typedef struct { /* This thread accepts an incoming connection and hands off the file * descriptor for the new connection to accept_fd_handoff() */ +#ifdef HAVE_LIBDISPATCH +static void socket_handoff(socket_handoff_t *handoff_data) { +#else static void *socket_handoff_thread(void *arg) { socket_handoff_t *handoff_data = (socket_handoff_t *)arg; +#endif + int launchd_fd = -1; int connected_fd; @@ -229,7 +241,9 @@ static void *socket_handoff_thread(void *arg) { fprintf(stderr, "X11.app Handing off fd to server thread via DarwinListenOnOpenFD(%d)\n", launchd_fd); DarwinListenOnOpenFD(launchd_fd); +#ifndef HAVE_LIBDISPATCH return NULL; +#endif } static int create_socket(char *filename_out) { @@ -298,8 +312,14 @@ kern_return_t do_request_fd_handoff_socket(mach_port_t port, string_t filename) } strlcpy(filename, handoff_data->filename, STRING_T_SIZE); - + +#ifdef HAVE_LIBDISPATCH + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), ^{ + socket_handoff(handoff_data); + }); +#else create_thread(socket_handoff_thread, handoff_data); +#endif #ifdef DEBUG fprintf(stderr, "X11.app: Thread created for handoff. Returning success to tell caller to connect and push the fd.\n");