summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Huddleston <jeremyhu@freedesktop.org>2008-11-19 11:42:59 -0800
committerJeremy Huddleston <jeremyhu@freedesktop.org>2008-11-21 10:59:10 -0800
commitd7ee76f9dd84da05b59591a971b96bf990136767 (patch)
tree695ea2a9f75ce3627f0ba77dcbb6acf9b65db630
parenta9e20306fbe3262602f21b876a52a1ef38cdf20a (diff)
XQuartz: pbproxy: Push the pbproxy Xevent processing into its own thread
and just have the AppKit thread wake it up. (cherry picked from commit 799715b8f3327c8da59ab45706e85af2d2c438e4)
-rw-r--r--hw/xquartz/pbproxy/main.m2
-rw-r--r--hw/xquartz/pbproxy/x-input.m33
2 files changed, 32 insertions, 3 deletions
diff --git a/hw/xquartz/pbproxy/main.m b/hw/xquartz/pbproxy/main.m
index e23956ed1..efa42e3a3 100644
--- a/hw/xquartz/pbproxy/main.m
+++ b/hw/xquartz/pbproxy/main.m
@@ -97,8 +97,6 @@ BOOL xpbproxy_init (void) {
return FALSE;
}
- xpbproxy_input_run();
-
[pool release];
return TRUE;
diff --git a/hw/xquartz/pbproxy/x-input.m b/hw/xquartz/pbproxy/x-input.m
index a03240fa9..ca7c30ddb 100644
--- a/hw/xquartz/pbproxy/x-input.m
+++ b/hw/xquartz/pbproxy/x-input.m
@@ -39,12 +39,39 @@
#include <unistd.h>
+#include <pthread.h>
+
static CFRunLoopSourceRef xpbproxy_dpy_source;
#ifdef STANDALONE_XPBPROXY
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 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_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;
@@ -164,10 +191,14 @@ static void x_input_callback (CFSocketRef sock, CFSocketCallBackType type,
}
#endif
- xpbproxy_input_run();
+ pthread_mutex_lock(&xpbproxy_dpy_lock);
+ pthread_cond_broadcast(&xpbproxy_dpy_cond);
+ pthread_mutex_unlock(&xpbproxy_dpy_lock);
}
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);
}