summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Huddleston <jeremyhu@apple.com>2011-04-21 16:31:58 -0700
committerJeremy Huddleston <jeremyhu@apple.com>2011-04-21 23:56:18 -0700
commit034538ea9b4770025e3573bc708039cabbe1e10d (patch)
treec5991643b5d7bd843b413453555c2b791a6881ed
parentca7b9e6c817681b9cec738e43cf020ac19b5e732 (diff)
XQuartz: Use dispatch_async to handoff the FD
Signed-off-by: Jeremy Huddleston <jeremyhu@apple.com>
-rw-r--r--hw/xquartz/mach-startup/bundle-main.c24
1 files changed, 22 insertions, 2 deletions
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 <stdio.h>
#include <string.h>
#include <stdlib.h>
-#include <pthread.h>
#include <stdbool.h>
#include <signal.h>
+#ifdef HAVE_LIBDISPATCH
+#include <dispatch/dispatch.h>
+#else
+#include <pthread.h>
+#endif
+
#include <sys/socket.h>
#include <sys/un.h>
@@ -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");