summaryrefslogtreecommitdiff
authorJeremy Huddleston <jeremyhu@freedesktop.org>2009-01-02 18:58:40 (GMT)
committer Jeremy Huddleston <jeremyhu@freedesktop.org>2009-01-02 19:02:36 (GMT)
commitadbfd49da2453b58a9e13b09c62e0611ea1c3f77 (patch) (side-by-side diff)
tree6f36bab61fa8b3514223ada9dd9c292673894cb7
parent0676a580fcc05d54049269028a34358935a4101c (diff)
downloadxserver-adbfd49da2453b58a9e13b09c62e0611ea1c3f77.zip
xserver-adbfd49da2453b58a9e13b09c62e0611ea1c3f77.tar.gz
XQuartz: pbproxy: Push dpy init and CFRunLoop hook setup into the pbproxy thread to avoid possible deadlock
(cherry picked from commit 49e59d32b88e4fad070f230b5efaa261b47f78db)
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--hw/xquartz/pbproxy/main.m29
-rw-r--r--hw/xquartz/pbproxy/pbproxy.h1
-rw-r--r--hw/xquartz/pbproxy/x-input.m21
3 files changed, 27 insertions, 24 deletions
diff --git a/hw/xquartz/pbproxy/main.m b/hw/xquartz/pbproxy/main.m
index 247ff74..5bc5182 100644
--- a/hw/xquartz/pbproxy/main.m
+++ b/hw/xquartz/pbproxy/main.m
@@ -68,7 +68,20 @@ static int x_error_handler (Display *dpy, XErrorEvent *errevent) {
return 0;
}
-BOOL xpbproxy_init (void) {
+static inline pthread_t create_thread(void *func, void *arg) {
+ pthread_attr_t attr;
+ pthread_t tid;
+
+ pthread_attr_init(&attr);
+ pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
+ pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+ pthread_create(&tid, &attr, func, arg);
+ pthread_attr_destroy(&attr);
+
+ return tid;
+}
+
+static void *xpbproxy_x_thread(void *args) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
size_t i;
@@ -89,7 +102,7 @@ BOOL xpbproxy_init (void) {
if (xpbproxy_dpy == NULL) {
fprintf (stderr, "xpbproxy: can't open default display\n");
[pool release];
- return FALSE;
+ return NULL;
}
XSetIOErrorHandler (x_io_error_handler);
@@ -99,7 +112,7 @@ BOOL xpbproxy_init (void) {
&xpbproxy_apple_wm_error_base)) {
fprintf (stderr, "xpbproxy: can't open AppleWM server extension\n");
[pool release];
- return FALSE;
+ return NULL;
}
xpbproxy_have_xfixes = XFixesQueryExtension(xpbproxy_dpy, &xpbproxy_xfixes_event_base, &xpbproxy_xfixes_error_base);
@@ -111,11 +124,17 @@ BOOL xpbproxy_init (void) {
if(!xpbproxy_input_register()) {
[pool release];
- return FALSE;
+ return NULL;
}
[pool release];
-
+
+ xpbproxy_input_loop();
+ return NULL;
+}
+
+BOOL xpbproxy_init (void) {
+ create_thread(xpbproxy_x_thread, NULL);
return TRUE;
}
diff --git a/hw/xquartz/pbproxy/pbproxy.h b/hw/xquartz/pbproxy/pbproxy.h
index d24d08b..a6798ef 100644
--- a/hw/xquartz/pbproxy/pbproxy.h
+++ b/hw/xquartz/pbproxy/pbproxy.h
@@ -76,6 +76,7 @@ extern BOOL xpbproxy_have_xfixes;
/* from x-input.m */
extern BOOL xpbproxy_input_register (void);
+extern void xpbproxy_input_loop();
#ifdef DEBUG
/* BEWARE: this can cause a string memory leak, according to the leaks program. */
diff --git a/hw/xquartz/pbproxy/x-input.m b/hw/xquartz/pbproxy/x-input.m
index acd01af..6ba30c6 100644
--- a/hw/xquartz/pbproxy/x-input.m
+++ b/hw/xquartz/pbproxy/x-input.m
@@ -50,19 +50,6 @@ BOOL xpbproxy_prefs_reload = NO;
static pthread_mutex_t xpbproxy_dpy_rdy_lock = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t xpbproxy_dpy_rdy_cond = PTHREAD_COND_INITIALIZER;
-static inline pthread_t create_thread(void *func, void *arg) {
- pthread_attr_t attr;
- pthread_t tid;
-
- pthread_attr_init(&attr);
- pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- pthread_create(&tid, &attr, func, arg);
- pthread_attr_destroy(&attr);
-
- return tid;
-}
-
/* Timestamp when the X server last told us it's active */
static Time last_activation_time;
@@ -101,7 +88,7 @@ static void x_event_apple_wm_notify(XAppleWMNotifyEvent *e) {
}
}
-static void *xpbproxy_input_thread(void *args) {
+void xpbproxy_input_loop() {
pthread_mutex_lock(&xpbproxy_dpy_rdy_lock);
while(true) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
@@ -153,8 +140,6 @@ static void *xpbproxy_input_thread(void *args) {
pthread_cond_wait(&xpbproxy_dpy_rdy_cond, &xpbproxy_dpy_rdy_lock);
}
-
- return NULL;
}
static BOOL add_input_socket (int sock, CFOptionFlags callback_types,
@@ -176,7 +161,7 @@ static BOOL add_input_socket (int sock, CFOptionFlags callback_types,
if (*cf_source == NULL)
return FALSE;
- CFRunLoopAddSource (CFRunLoopGetCurrent (),
+ CFRunLoopAddSource (CFRunLoopGetMain (),
*cf_source, kCFRunLoopDefaultMode);
return TRUE;
}
@@ -197,8 +182,6 @@ static void x_input_callback (CFSocketRef sock, CFSocketCallBackType type,
}
BOOL xpbproxy_input_register(void) {
- create_thread(xpbproxy_input_thread, NULL);
-
return add_input_socket(ConnectionNumber(xpbproxy_dpy), kCFSocketReadCallBack,
x_input_callback, NULL, &xpbproxy_dpy_source);
}