summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Huddleston <jeremyhu@freedesktop.org>2008-12-21 22:43:12 (GMT)
committerJeremy Huddleston <jeremyhu@freedesktop.org>2008-12-22 05:35:20 (GMT)
commit4c256c0e9c4fe61990343c8bcf2e352c83d76e69 (patch)
tree12bdbc68260e460f50785e7a7e97b405ed01560e
parentecc3a7b6090552c309fe8e264d527ddd666a5761 (diff)
XQuartz: pbproxy: Release display notification lock when not needed to avoid deadlock
(cherry picked from commit 22f664ab95a0cae981e9cefad6f075d051583ca5)
-rw-r--r--hw/xquartz/pbproxy/pbproxy.h1
-rw-r--r--hw/xquartz/pbproxy/x-input.m108
2 files changed, 54 insertions, 55 deletions
diff --git a/hw/xquartz/pbproxy/pbproxy.h b/hw/xquartz/pbproxy/pbproxy.h
index eb1f3ba..d24d08b 100644
--- a/hw/xquartz/pbproxy/pbproxy.h
+++ b/hw/xquartz/pbproxy/pbproxy.h
@@ -76,7 +76,6 @@ extern BOOL xpbproxy_have_xfixes;
/* from x-input.m */
extern BOOL xpbproxy_input_register (void);
-extern void xpbproxy_input_run (void);
#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 ca7c30d..acd01af 100644
--- a/hw/xquartz/pbproxy/x-input.m
+++ b/hw/xquartz/pbproxy/x-input.m
@@ -47,8 +47,8 @@ static CFRunLoopSourceRef xpbproxy_dpy_source;
BOOL xpbproxy_prefs_reload = NO;
#endif
-static pthread_mutex_t xpbproxy_dpy_lock = PTHREAD_MUTEX_INITIALIZER;
-static pthread_cond_t xpbproxy_dpy_cond = PTHREAD_COND_INITIALIZER;
+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;
@@ -63,15 +63,6 @@ static inline pthread_t create_thread(void *func, void *arg) {
return tid;
}
-static void *xpbproxy_input_thread(void *args) {
- pthread_mutex_lock(&xpbproxy_dpy_lock);
- while(true) {
- xpbproxy_input_run();
- pthread_cond_wait(&xpbproxy_dpy_cond, &xpbproxy_dpy_lock);
- }
-}
-
-
/* Timestamp when the X server last told us it's active */
static Time last_activation_time;
@@ -110,51 +101,60 @@ static void x_event_apple_wm_notify(XAppleWMNotifyEvent *e) {
}
}
-void xpbproxy_input_run (void) {
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-
- if (nil == pool)
- {
- fprintf(stderr, "unable to allocate/init auto release pool!\n");
- return;
- }
-
- while (XPending (xpbproxy_dpy) != 0) {
- XEvent e;
- XNextEvent (xpbproxy_dpy, &e);
+static void *xpbproxy_input_thread(void *args) {
+ pthread_mutex_lock(&xpbproxy_dpy_rdy_lock);
+ while(true) {
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- switch (e.type) {
- case SelectionClear:
- if([xpbproxy_selection_object() is_active])
- [xpbproxy_selection_object () clear_event:&e.xselectionclear];
- break;
-
- case SelectionRequest:
- [xpbproxy_selection_object () request_event:&e.xselectionrequest];
- break;
-
- case SelectionNotify:
- [xpbproxy_selection_object () notify_event:&e.xselection];
- break;
-
- case PropertyNotify:
- [xpbproxy_selection_object () property_event:&e.xproperty];
- break;
-
- default:
- if(e.type >= xpbproxy_apple_wm_event_base &&
- e.type < xpbproxy_apple_wm_event_base + AppleWMNumberEvents) {
- x_event_apple_wm_notify((XAppleWMNotifyEvent *) &e);
- } else if(e.type == xpbproxy_xfixes_event_base + XFixesSelectionNotify) {
- [xpbproxy_selection_object() xfixes_selection_notify:(XFixesSelectionNotifyEvent *)&e];
- }
- break;
+ if(pool == nil) {
+ fprintf(stderr, "unable to allocate/init auto release pool!\n");
+ break;
}
- XFlush(xpbproxy_dpy);
+ while (XPending(xpbproxy_dpy) != 0) {
+ XEvent e;
+
+ pthread_mutex_unlock(&xpbproxy_dpy_rdy_lock);
+ XNextEvent (xpbproxy_dpy, &e);
+
+ switch (e.type) {
+ case SelectionClear:
+ if([xpbproxy_selection_object() is_active])
+ [xpbproxy_selection_object () clear_event:&e.xselectionclear];
+ break;
+
+ case SelectionRequest:
+ [xpbproxy_selection_object () request_event:&e.xselectionrequest];
+ break;
+
+ case SelectionNotify:
+ [xpbproxy_selection_object () notify_event:&e.xselection];
+ break;
+
+ case PropertyNotify:
+ [xpbproxy_selection_object () property_event:&e.xproperty];
+ break;
+
+ default:
+ if(e.type >= xpbproxy_apple_wm_event_base &&
+ e.type < xpbproxy_apple_wm_event_base + AppleWMNumberEvents) {
+ x_event_apple_wm_notify((XAppleWMNotifyEvent *) &e);
+ } else if(e.type == xpbproxy_xfixes_event_base + XFixesSelectionNotify) {
+ [xpbproxy_selection_object() xfixes_selection_notify:(XFixesSelectionNotifyEvent *)&e];
+ }
+ break;
+ }
+
+ XFlush(xpbproxy_dpy);
+ pthread_mutex_lock(&xpbproxy_dpy_rdy_lock);
+ }
+
+ [pool release];
+
+ pthread_cond_wait(&xpbproxy_dpy_rdy_cond, &xpbproxy_dpy_rdy_lock);
}
- [pool release];
+ return NULL;
}
static BOOL add_input_socket (int sock, CFOptionFlags callback_types,
@@ -191,9 +191,9 @@ static void x_input_callback (CFSocketRef sock, CFSocketCallBackType type,
}
#endif
- pthread_mutex_lock(&xpbproxy_dpy_lock);
- pthread_cond_broadcast(&xpbproxy_dpy_cond);
- pthread_mutex_unlock(&xpbproxy_dpy_lock);
+ pthread_mutex_lock(&xpbproxy_dpy_rdy_lock);
+ pthread_cond_broadcast(&xpbproxy_dpy_rdy_cond);
+ pthread_mutex_unlock(&xpbproxy_dpy_rdy_lock);
}
BOOL xpbproxy_input_register(void) {