XQuartz: pbproxy: Push dpy init and CFRunLoop hook setup into the pbproxy thread to avoid possible deadlock
This commit is contained in:
parent
5ac87d00b2
commit
49e59d32b8
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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. */
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user