summaryrefslogtreecommitdiff
path: root/mi
diff options
context:
space:
mode:
authorJeremy Huddleston <jeremyhu@freedesktop.org>2009-01-16 13:54:08 -0800
committerEric Anholt <eric@anholt.net>2009-01-30 16:44:49 -0800
commite81b4d495ba02d4fc0b05c26a53fd2a816a61eaa (patch)
tree35a9ae9e51f6f2c9d12487996e0531d13b87ba45 /mi
parentd6498ea62117cce6a00ac045ddeefb7268a70f5b (diff)
XQuartz: mieq: Wait for the server to finish initializing before letting other threads mieqEnqueue
Avoid possible race condition whereby one thread might call mieqEnqueue before InitAndStartDevices finishes (cherry picked from commit 94e417ac87a98cd5c6bf2d7c495d702748398931)
Diffstat (limited to 'mi')
-rw-r--r--mi/mieq.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/mi/mieq.c b/mi/mieq.c
index 15ba8e723..8d68ca1f8 100644
--- a/mi/mieq.c
+++ b/mi/mieq.c
@@ -36,11 +36,6 @@ in this Software without prior written authorization from The Open Group.
#include <dix-config.h>
#endif
-#ifdef XQUARTZ
-#include <pthread.h>
-static pthread_mutex_t miEventQueueMutex = PTHREAD_MUTEX_INITIALIZER;
-#endif
-
# define NEED_EVENTS
# include <X11/X.h>
# include <X11/Xmd.h>
@@ -87,6 +82,25 @@ typedef struct _EventQueue {
static EventQueueRec miEventQueue;
static EventListPtr masterEvents; /* for use in mieqProcessInputEvents */
+#ifdef XQUARTZ
+#include <pthread.h>
+static pthread_mutex_t miEventQueueMutex = PTHREAD_MUTEX_INITIALIZER;
+
+extern BOOL serverInitComplete;
+extern pthread_mutex_t serverInitCompleteMutex;
+extern pthread_cond_t serverInitCompleteCond;
+
+static inline void wait_for_server_init(void) {
+ /* If the server hasn't finished initializing, wait for it... */
+ if(!serverInitComplete) {
+ pthread_mutex_lock(&serverInitCompleteMutex);
+ while(!serverInitComplete)
+ pthread_cond_wait(&serverInitCompleteCond, &serverInitCompleteMutex);
+ pthread_mutex_unlock(&serverInitCompleteMutex);
+ }
+}
+#endif
+
Bool
mieqInit(void)
{
@@ -145,6 +159,7 @@ mieqEnqueue(DeviceIntPtr pDev, xEvent *e)
int evlen;
#ifdef XQUARTZ
+ wait_for_server_init();
pthread_mutex_lock(&miEventQueueMutex);
#endif