diff options
author | Jeremy Huddleston <jeremyhu@freedesktop.org> | 2009-01-16 13:54:08 -0800 |
---|---|---|
committer | Jeremy Huddleston <jeremyhu@freedesktop.org> | 2009-01-16 13:54:08 -0800 |
commit | 94e417ac87a98cd5c6bf2d7c495d702748398931 (patch) | |
tree | b18fb9b71616c07f244698454a68ad3b7f78ec78 | |
parent | e917a1cd30f720e6e51253c5041f02232522c9af (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
-rw-r--r-- | dix/main.c | 14 | ||||
-rw-r--r-- | mi/mieq.c | 25 |
2 files changed, 34 insertions, 5 deletions
diff --git a/dix/main.c b/dix/main.c index ee2e10db5..0527621e7 100644 --- a/dix/main.c +++ b/dix/main.c @@ -234,6 +234,12 @@ static int indexForScanlinePad[ 65 ] = { #endif #ifdef XQUARTZ +#include <pthread.h> + +BOOL serverInitComplete = FALSE; +pthread_mutex_t serverInitCompleteMutex = PTHREAD_MUTEX_INITIALIZER; +pthread_cond_t serverInitCompleteCond = PTHREAD_COND_INITIALIZER; + int dix_main(int argc, char *argv[], char *envp[]) #else int main(int argc, char *argv[], char *envp[]) @@ -378,6 +384,14 @@ int main(int argc, char *argv[], char *envp[]) } } +#ifdef XQUARTZ + /* Let the other threads know the server is done with its init */ + pthread_mutex_lock(&serverInitCompleteMutex); + serverInitComplete = TRUE; + pthread_cond_broadcast(&serverInitCompleteCond); + pthread_mutex_unlock(&serverInitCompleteMutex); +#endif + NotifyParentProcess(); Dispatch(); @@ -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 |