XQuartz: pbproxy: Release display notification lock when not needed to avoid deadlock

(cherry picked from commit 22f664ab95)
This commit is contained in:
Jeremy Huddleston 2008-12-21 14:43:12 -08:00
parent b1f166f298
commit 029d255a65
2 changed files with 54 additions and 55 deletions

View File

@ -76,7 +76,6 @@ extern BOOL xpbproxy_have_xfixes;
/* from x-input.m */ /* from x-input.m */
extern BOOL xpbproxy_input_register (void); extern BOOL xpbproxy_input_register (void);
extern void xpbproxy_input_run (void);
#ifdef DEBUG #ifdef DEBUG
/* BEWARE: this can cause a string memory leak, according to the leaks program. */ /* BEWARE: this can cause a string memory leak, according to the leaks program. */

View File

@ -47,8 +47,8 @@ static CFRunLoopSourceRef xpbproxy_dpy_source;
BOOL xpbproxy_prefs_reload = NO; BOOL xpbproxy_prefs_reload = NO;
#endif #endif
static pthread_mutex_t xpbproxy_dpy_lock = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t xpbproxy_dpy_rdy_lock = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t xpbproxy_dpy_cond = PTHREAD_COND_INITIALIZER; static pthread_cond_t xpbproxy_dpy_rdy_cond = PTHREAD_COND_INITIALIZER;
static inline pthread_t create_thread(void *func, void *arg) { static inline pthread_t create_thread(void *func, void *arg) {
pthread_attr_t attr; pthread_attr_t attr;
@ -63,15 +63,6 @@ static inline pthread_t create_thread(void *func, void *arg) {
return tid; 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 */ /* Timestamp when the X server last told us it's active */
static Time last_activation_time; static Time last_activation_time;
@ -110,17 +101,20 @@ static void x_event_apple_wm_notify(XAppleWMNotifyEvent *e) {
} }
} }
void xpbproxy_input_run (void) { static void *xpbproxy_input_thread(void *args) {
pthread_mutex_lock(&xpbproxy_dpy_rdy_lock);
while(true) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
if (nil == pool) if(pool == nil) {
{
fprintf(stderr, "unable to allocate/init auto release pool!\n"); fprintf(stderr, "unable to allocate/init auto release pool!\n");
return; break;
} }
while (XPending(xpbproxy_dpy) != 0) { while (XPending(xpbproxy_dpy) != 0) {
XEvent e; XEvent e;
pthread_mutex_unlock(&xpbproxy_dpy_rdy_lock);
XNextEvent (xpbproxy_dpy, &e); XNextEvent (xpbproxy_dpy, &e);
switch (e.type) { switch (e.type) {
@ -152,9 +146,15 @@ void xpbproxy_input_run (void) {
} }
XFlush(xpbproxy_dpy); XFlush(xpbproxy_dpy);
pthread_mutex_lock(&xpbproxy_dpy_rdy_lock);
} }
[pool release]; [pool release];
pthread_cond_wait(&xpbproxy_dpy_rdy_cond, &xpbproxy_dpy_rdy_lock);
}
return NULL;
} }
static BOOL add_input_socket (int sock, CFOptionFlags callback_types, static BOOL add_input_socket (int sock, CFOptionFlags callback_types,
@ -191,9 +191,9 @@ static void x_input_callback (CFSocketRef sock, CFSocketCallBackType type,
} }
#endif #endif
pthread_mutex_lock(&xpbproxy_dpy_lock); pthread_mutex_lock(&xpbproxy_dpy_rdy_lock);
pthread_cond_broadcast(&xpbproxy_dpy_cond); pthread_cond_broadcast(&xpbproxy_dpy_rdy_cond);
pthread_mutex_unlock(&xpbproxy_dpy_lock); pthread_mutex_unlock(&xpbproxy_dpy_rdy_lock);
} }
BOOL xpbproxy_input_register(void) { BOOL xpbproxy_input_register(void) {