xserver: Branch 'xorg-server-1.5-apple'

Jeremy Huddleston jeremyhu at kemper.freedesktop.org
Fri Jan 2 11:02:37 PST 2009


 hw/xquartz/pbproxy/main.m    |   29 ++++++++++++++++++++++++-----
 hw/xquartz/pbproxy/pbproxy.h |    1 +
 hw/xquartz/pbproxy/x-input.m |   21 ++-------------------
 3 files changed, 27 insertions(+), 24 deletions(-)

New commits:
commit 7bdcfad9b5f31a684c1db2d2369338033d589c6a
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date:   Fri Jan 2 10:58:40 2009 -0800

    XQuartz: pbproxy: Push dpy init and CFRunLoop hook setup into the pbproxy thread to avoid possible deadlock
    (cherry picked from commit 49e59d32b88e4fad070f230b5efaa261b47f78db)

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);
 }


More information about the xorg-commit mailing list