mirror of
https://gitlab.freedesktop.org/xorg/xserver.git
synced 2026-01-07 21:50:14 +01:00
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 94e417ac87)
This commit is contained in:
parent
b1c2d711e7
commit
2db1d46bac
2 changed files with 34 additions and 5 deletions
14
dix/main.c
14
dix/main.c
|
|
@ -238,6 +238,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[])
|
||||
|
|
@ -428,6 +434,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();
|
||||
|
|
|
|||
25
mi/mieq.c
25
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>
|
||||
|
|
@ -84,6 +79,25 @@ typedef struct _EventQueue {
|
|||
|
||||
static EventQueueRec miEventQueue;
|
||||
|
||||
#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)
|
||||
{
|
||||
|
|
@ -111,6 +125,7 @@ void
|
|||
mieqEnqueue(DeviceIntPtr pDev, xEvent *e)
|
||||
{
|
||||
#ifdef XQUARTZ
|
||||
wait_for_server_init();
|
||||
pthread_mutex_lock(&miEventQueueMutex);
|
||||
#endif
|
||||
unsigned int oldtail = miEventQueue.tail;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue