From 2a1ba20af98c0e9a6a7f1a50d32058dcc9759c21 Mon Sep 17 00:00:00 2001 From: Jeremy Huddleston Date: Thu, 17 Apr 2008 15:23:00 -0700 Subject: [PATCH] XQuartz: Use a mutex to ensure we only have one thread calling mieqEnqueue at a time. (cherry picked from commit 7b087c965bce9f440ab5233d6383aa4a7de969b8) --- hw/xquartz/darwinEvents.c | 244 ++++++++++++++++++++++---------------- hw/xquartz/darwinEvents.h | 1 - hw/xquartz/threadSafety.c | 2 +- hw/xquartz/threadSafety.h | 3 + 4 files changed, 148 insertions(+), 102 deletions(-) diff --git a/hw/xquartz/darwinEvents.c b/hw/xquartz/darwinEvents.c index 260690ce5..c59359625 100644 --- a/hw/xquartz/darwinEvents.c +++ b/hw/xquartz/darwinEvents.c @@ -54,6 +54,9 @@ in this Software without prior written authorization from The Open Group. #include #include #include +#include +#include + #include /* Fake button press/release for scroll wheel move. */ @@ -77,6 +80,25 @@ static int old_flags = 0; // last known modifier state xEvent *darwinEvents = NULL; +pthread_mutex_t mieqEnqueue_mutex; +static inline void mieqEnqueue_lock(void) { + int err; + if((err = pthread_mutex_lock(&mieqEnqueue_mutex))) { + ErrorF("%s:%s:%d: Failed to lock mieqEnqueue_mutex: %d\n", + __FILE__, __FUNCTION__, __LINE__, err); + spewCallStack(); + } +} + +static inline void mieqEnqueue_unlock(void) { + int err; + if((err = pthread_mutex_unlock(&mieqEnqueue_mutex))) { + ErrorF("%s:%s:%d: Failed to unlock mieqEnqueue_mutex: %d\n", + __FILE__, __FUNCTION__, __LINE__, err); + spewCallStack(); + } +} + /* * DarwinPressModifierMask * Press or release the given modifier key, specified by its mask. @@ -197,107 +219,119 @@ static void DarwinSimulateMouseClick( mieqSetHandler. */ void DarwinEventHandler(int screenNum, xEventPtr xe, DeviceIntPtr dev, int nevents) { - int i; - - DEBUG_LOG("DarwinEventHandler(%d, %p, %p, %d)\n", screenNum, xe, dev, nevents); - for (i=0; i oh, i ... er ... christ. @@ -398,15 +434,18 @@ void DarwinSendPointerEvents(int ev_type, int ev_button, int pointer_x, int poin return; } - num_events = GetPointerEvents(darwinEvents, darwinPointer, ev_type, ev_button, - POINTER_ABSOLUTE, 0, 5, valuators); - - for(i=0; i