XQuartz: Don't call mieqEnqueue during server shutdown

Found-by: GuardMalloc
Signed-off-by: Jeremy Huddleston <jeremyhu@apple.com>
This commit is contained in:
Jeremy Huddleston 2011-05-14 16:11:32 -07:00
parent fd5f630bc4
commit 25191648b8
4 changed files with 35 additions and 28 deletions

View File

@ -121,9 +121,9 @@ extern void Dispatch(void);
#ifdef XQUARTZ #ifdef XQUARTZ
#include <pthread.h> #include <pthread.h>
BOOL serverInitComplete = FALSE; BOOL serverRunning = FALSE;
pthread_mutex_t serverInitCompleteMutex = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t serverRunningMutex = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t serverInitCompleteCond = PTHREAD_COND_INITIALIZER; pthread_cond_t serverRunningCond = PTHREAD_COND_INITIALIZER;
int dix_main(int argc, char *argv[], char *envp[]); int dix_main(int argc, char *argv[], char *envp[]);
@ -277,18 +277,25 @@ int main(int argc, char *argv[], char *envp[])
} }
#ifdef XQUARTZ #ifdef XQUARTZ
/* Let the other threads know the server is done with its init */ /* Let the other threads know the server is done with its init */
pthread_mutex_lock(&serverInitCompleteMutex); pthread_mutex_lock(&serverRunningMutex);
serverInitComplete = TRUE; serverRunning = TRUE;
pthread_cond_broadcast(&serverInitCompleteCond); pthread_cond_broadcast(&serverRunningCond);
pthread_mutex_unlock(&serverInitCompleteMutex); pthread_mutex_unlock(&serverRunningMutex);
#endif #endif
NotifyParentProcess(); NotifyParentProcess();
Dispatch(); Dispatch();
UndisplayDevices(); #ifdef XQUARTZ
/* Let the other threads know the server is no longer running */
pthread_mutex_lock(&serverRunningMutex);
serverRunning = FALSE;
pthread_mutex_unlock(&serverRunningMutex);
#endif
UndisplayDevices();
/* Now free up whatever must be freed */ /* Now free up whatever must be freed */
if (screenIsSaved == SCREEN_SAVER_ON) if (screenIsSaved == SCREEN_SAVER_ON)

View File

@ -39,9 +39,9 @@ CFStringRef app_prefs_domain_cfstr;
/* Stubs */ /* Stubs */
char *display = NULL; char *display = NULL;
BOOL serverInitComplete = YES; BOOL serverRunning = YES;
pthread_mutex_t serverInitCompleteMutex = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t serverRunningMutex = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t serverInitCompleteCond = PTHREAD_COND_INITIALIZER; pthread_cond_t serverRunningCond = PTHREAD_COND_INITIALIZER;
static void signal_handler (int sig) { static void signal_handler (int sig) {
switch(sig) { switch(sig) {

View File

@ -47,17 +47,17 @@ BOOL xpbproxy_is_standalone = NO;
x_selection *_selection_object; x_selection *_selection_object;
extern BOOL serverInitComplete; extern BOOL serverRunning;
extern pthread_mutex_t serverInitCompleteMutex; extern pthread_mutex_t serverRunningMutex;
extern pthread_cond_t serverInitCompleteCond; extern pthread_cond_t serverRunningCond;
static inline void wait_for_server_init(void) { static inline void wait_for_server_init(void) {
/* If the server hasn't finished initializing, wait for it... */ /* If the server hasn't finished initializing, wait for it... */
if(!serverInitComplete) { if(!serverRunning) {
pthread_mutex_lock(&serverInitCompleteMutex); pthread_mutex_lock(&serverRunningMutex);
while(!serverInitComplete) while(!serverRunning)
pthread_cond_wait(&serverInitCompleteCond, &serverInitCompleteMutex); pthread_cond_wait(&serverRunningCond, &serverRunningMutex);
pthread_mutex_unlock(&serverInitCompleteMutex); pthread_mutex_unlock(&serverRunningMutex);
} }
} }

View File

@ -83,17 +83,17 @@ static EventQueueRec miEventQueue;
#include <pthread.h> #include <pthread.h>
static pthread_mutex_t miEventQueueMutex = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t miEventQueueMutex = PTHREAD_MUTEX_INITIALIZER;
extern BOOL serverInitComplete; extern BOOL serverRunning;
extern pthread_mutex_t serverInitCompleteMutex; extern pthread_mutex_t serverRunningMutex;
extern pthread_cond_t serverInitCompleteCond; extern pthread_cond_t serverRunningCond;
static inline void wait_for_server_init(void) { static inline void wait_for_server_init(void) {
/* If the server hasn't finished initializing, wait for it... */ /* If the server hasn't finished initializing, wait for it... */
if(!serverInitComplete) { if(!serverRunning) {
pthread_mutex_lock(&serverInitCompleteMutex); pthread_mutex_lock(&serverRunningMutex);
while(!serverInitComplete) while(!serverRunning)
pthread_cond_wait(&serverInitCompleteCond, &serverInitCompleteMutex); pthread_cond_wait(&serverRunningCond, &serverRunningMutex);
pthread_mutex_unlock(&serverInitCompleteMutex); pthread_mutex_unlock(&serverRunningMutex);
} }
} }
#endif #endif