XQuartz: Added locking into mieq to protect X from eating itself
This commit is contained in:
parent
4a653c6bfd
commit
4904e04ce6
45
mi/mieq.c
45
mi/mieq.c
|
@ -36,6 +36,11 @@ 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>
|
||||
|
@ -105,6 +110,9 @@ mieqInit(void)
|
|||
void
|
||||
mieqEnqueue(DeviceIntPtr pDev, xEvent *e)
|
||||
{
|
||||
#ifdef XQUARTZ
|
||||
pthread_mutex_lock(&miEventQueueMutex);
|
||||
#endif
|
||||
unsigned int oldtail = miEventQueue.tail, newtail;
|
||||
int isMotion = 0;
|
||||
deviceValuator *v = (deviceValuator *) e;
|
||||
|
@ -123,6 +131,9 @@ mieqEnqueue(DeviceIntPtr pDev, xEvent *e)
|
|||
if (e->u.u.type == DeviceValuator) {
|
||||
if (laste->nevents > 6) {
|
||||
ErrorF("mieqEnqueue: more than six valuator events; dropping.\n");
|
||||
#ifdef XQUARTZ
|
||||
pthread_mutex_unlock(&miEventQueueMutex);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
if (oldtail == miEventQueue.head ||
|
||||
|
@ -134,9 +145,15 @@ mieqEnqueue(DeviceIntPtr pDev, xEvent *e)
|
|||
((lastkbp->deviceid & DEVICE_BITS) !=
|
||||
(v->deviceid & DEVICE_BITS))) {
|
||||
ErrorF("mieqEnequeue: out-of-order valuator event; dropping.\n");
|
||||
#ifdef XQUARTZ
|
||||
pthread_mutex_unlock(&miEventQueueMutex);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
memcpy(&(laste->event[laste->nevents++]), e, sizeof(xEvent));
|
||||
#ifdef XQUARTZ
|
||||
pthread_mutex_unlock(&miEventQueueMutex);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -151,7 +168,10 @@ mieqEnqueue(DeviceIntPtr pDev, xEvent *e)
|
|||
* handled. */
|
||||
if (newtail == miEventQueue.head) {
|
||||
ErrorF("tossed event which came in late\n");
|
||||
return;
|
||||
#ifdef XQUARTZ
|
||||
pthread_mutex_unlock(&miEventQueueMutex);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
miEventQueue.tail = newtail;
|
||||
}
|
||||
|
@ -172,24 +192,39 @@ mieqEnqueue(DeviceIntPtr pDev, xEvent *e)
|
|||
miEventQueue.events[oldtail].pDev = pDev;
|
||||
|
||||
miEventQueue.lastMotion = isMotion;
|
||||
#ifdef XQUARTZ
|
||||
pthread_mutex_unlock(&miEventQueueMutex);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
mieqSwitchScreen(ScreenPtr pScreen, Bool fromDIX)
|
||||
{
|
||||
#ifdef XQUARTZ
|
||||
pthread_mutex_lock(&miEventQueueMutex);
|
||||
#endif
|
||||
miEventQueue.pEnqueueScreen = pScreen;
|
||||
if (fromDIX)
|
||||
miEventQueue.pDequeueScreen = pScreen;
|
||||
#ifdef XQUARTZ
|
||||
pthread_mutex_unlock(&miEventQueueMutex);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
mieqSetHandler(int event, mieqHandler handler)
|
||||
{
|
||||
#ifdef XQUARTZ
|
||||
pthread_mutex_lock(&miEventQueueMutex);
|
||||
#endif
|
||||
if (handler && miEventQueue.handlers[event])
|
||||
ErrorF("mieq: warning: overriding existing handler %p with %p for "
|
||||
"event %d\n", miEventQueue.handlers[event], handler, event);
|
||||
|
||||
miEventQueue.handlers[event] = handler;
|
||||
#ifdef XQUARTZ
|
||||
pthread_mutex_unlock(&miEventQueueMutex);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Call this from ProcessInputEvents(). */
|
||||
|
@ -200,6 +235,10 @@ mieqProcessInputEvents(void)
|
|||
int x = 0, y = 0;
|
||||
DeviceIntPtr dev = NULL;
|
||||
|
||||
#ifdef XQUARTZ
|
||||
pthread_mutex_lock(&miEventQueueMutex);
|
||||
#endif
|
||||
|
||||
while (miEventQueue.head != miEventQueue.tail) {
|
||||
if (screenIsSaved == SCREEN_SAVER_ON)
|
||||
SaveScreens (SCREEN_SAVER_OFF, ScreenSaverReset);
|
||||
|
@ -220,7 +259,6 @@ mieqProcessInputEvents(void)
|
|||
miEventQueue.handlers[e->event->u.u.type](miEventQueue.pDequeueScreen->myNum,
|
||||
e->event, dev,
|
||||
e->nevents);
|
||||
return;
|
||||
}
|
||||
else if (e->pScreen != miEventQueue.pDequeueScreen) {
|
||||
/* Assumption - screen switching can only occur on motion events. */
|
||||
|
@ -250,4 +288,7 @@ mieqProcessInputEvents(void)
|
|||
dev->public.processInputProc(e->event, dev, e->nevents);
|
||||
}
|
||||
}
|
||||
#ifdef XQUARTZ
|
||||
pthread_mutex_unlock(&miEventQueueMutex);
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user