diff --git a/dix/main.c b/dix/main.c index 0fa561e18..4947062a5 100644 --- a/dix/main.c +++ b/dix/main.c @@ -120,12 +120,6 @@ Equipment Corporation. extern void Dispatch(void); -#ifdef XQUARTZ -BOOL serverRunning; -pthread_mutex_t serverRunningMutex = PTHREAD_MUTEX_INITIALIZER; -pthread_cond_t serverRunningCond = PTHREAD_COND_INITIALIZER; -#endif - CallbackListPtr RootWindowFinalizeCallback = NULL; int @@ -286,27 +280,12 @@ dix_main(int argc, char *argv[], char *envp[]) } } -#ifdef XQUARTZ - /* Let the other threads know the server is done with its init */ - pthread_mutex_lock(&serverRunningMutex); - serverRunning = TRUE; - pthread_cond_broadcast(&serverRunningCond); - pthread_mutex_unlock(&serverRunningMutex); -#endif - NotifyParentProcess(); InputThreadInit(); Dispatch(); -#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(); DisableAllDevices(); diff --git a/hw/xquartz/X11Application.m b/hw/xquartz/X11Application.m index 19e9451f7..768eecf68 100644 --- a/hw/xquartz/X11Application.m +++ b/hw/xquartz/X11Application.m @@ -1311,9 +1311,7 @@ untrusted_str(NSEvent *e) #endif extern void -darwinEvents_lock(void); -extern void -darwinEvents_unlock(void); +wait_for_mieq_init(void); - (void) sendX11NSEvent:(NSEvent *)e { @@ -1329,8 +1327,7 @@ darwinEvents_unlock(void); if (!darwinTabletCurrent) { /* Ensure that the event system is initialized */ - darwinEvents_lock(); - darwinEvents_unlock(); + wait_for_mieq_init(); assert(darwinTabletStylus); tilt = NSZeroPoint; diff --git a/hw/xquartz/darwinEvents.c b/hw/xquartz/darwinEvents.c index 7f34e0c68..a3b70f569 100644 --- a/hw/xquartz/darwinEvents.c +++ b/hw/xquartz/darwinEvents.c @@ -92,10 +92,30 @@ static pthread_mutex_t fd_add_lock = PTHREAD_MUTEX_INITIALIZER; static pthread_cond_t fd_add_ready_cond = PTHREAD_COND_INITIALIZER; static pthread_t fd_add_tid = NULL; -static InternalEvent* darwinEvents = NULL; +static BOOL mieqInitialized; +static pthread_mutex_t mieqInitializedMutex = PTHREAD_MUTEX_INITIALIZER; +static pthread_cond_t mieqInitializedCond = PTHREAD_COND_INITIALIZER; -static pthread_mutex_t mieq_lock = PTHREAD_MUTEX_INITIALIZER; -static pthread_cond_t mieq_ready_cond = PTHREAD_COND_INITIALIZER; +extern inline void +wait_for_mieq_init(void) +{ + if (!mieqInitialized) { + pthread_mutex_lock(&mieqInitializedMutex); + while (!mieqInitialized) { + pthread_cond_wait(&mieqInitializedCond, &mieqInitializedMutex); + } + pthread_mutex_unlock(&mieqInitializedMutex); + } +} + +static inline void +signal_mieq_init(void) +{ + pthread_mutex_lock(&mieqInitializedMutex); + mieqInitialized = TRUE; + pthread_cond_broadcast(&mieqInitializedCond); + pthread_mutex_unlock(&mieqInitializedMutex); +} /*** Pthread Magics ***/ static pthread_t @@ -113,35 +133,6 @@ create_thread(void *(*func)(void *), void *arg) return tid; } -void -darwinEvents_lock(void); -void -darwinEvents_lock(void) -{ - int err; - if ((err = pthread_mutex_lock(&mieq_lock))) { - ErrorF("%s:%s:%d: Failed to lock mieq_lock: %d\n", - __FILE__, __FUNCTION__, __LINE__, err); - xorg_backtrace(); - } - if (darwinEvents == NULL) { - pthread_cond_wait(&mieq_ready_cond, &mieq_lock); - } -} - -void -darwinEvents_unlock(void); -void -darwinEvents_unlock(void) -{ - int err; - if ((err = pthread_mutex_unlock(&mieq_lock))) { - ErrorF("%s:%s:%d: Failed to unlock mieq_lock: %d\n", - __FILE__, __FUNCTION__, __LINE__, err); - xorg_backtrace(); - } -} - /* * DarwinPressModifierKey * Press or release the given modifier key (one of NX_MODIFIERKEY_* constants) @@ -379,24 +370,11 @@ DarwinEQInit(void) mieqInit(); mieqSetHandler(ET_XQuartz, DarwinEventHandler); - /* Note that this *could* cause a potential async issue, since we're checking - * darwinEvents without holding the lock, but darwinEvents is only ever set - * here, so I don't bother. - */ - if (!darwinEvents) { - darwinEvents = InitEventList(GetMaximumEventsNum()); - - if (!darwinEvents) - FatalError("Couldn't allocate event buffer\n"); - - darwinEvents_lock(); - pthread_cond_broadcast(&mieq_ready_cond); - darwinEvents_unlock(); - } - if (!fd_add_tid) fd_add_tid = create_thread(DarwinProcessFDAdditionQueue_thread, NULL); + signal_mieq_init(); + return TRUE; } @@ -437,7 +415,7 @@ DarwinPokeEQ(void) void DarwinInputReleaseButtonsAndKeys(DeviceIntPtr pDev) { - darwinEvents_lock(); + input_lock(); { int i; if (pDev->button) { @@ -458,7 +436,7 @@ DarwinInputReleaseButtonsAndKeys(DeviceIntPtr pDev) } } DarwinPokeEQ(); - } darwinEvents_unlock(); + } input_unlock(); } void @@ -470,12 +448,6 @@ DarwinSendTabletEvents(DeviceIntPtr pDev, int ev_type, int ev_button, ScreenPtr screen; ValuatorMask valuators; - if (!darwinEvents) { - DEBUG_LOG("%s called before darwinEvents was initialized\n", - __FUNCTION__); - return; - } - screen = miPointerGetScreen(pDev); if (!screen) { DEBUG_LOG("%s called before screen was initialized\n", @@ -498,7 +470,7 @@ DarwinSendTabletEvents(DeviceIntPtr pDev, int ev_type, int ev_button, valuator_mask_set_double(&valuators, 3, XQUARTZ_VALUATOR_LIMIT * tilt_x); valuator_mask_set_double(&valuators, 4, XQUARTZ_VALUATOR_LIMIT * tilt_y); - darwinEvents_lock(); + input_lock(); { if (ev_type == ProximityIn || ev_type == ProximityOut) { QueueProximityEvents(pDev, ev_type, &valuators); @@ -507,7 +479,7 @@ DarwinSendTabletEvents(DeviceIntPtr pDev, int ev_type, int ev_button, &valuators); } DarwinPokeEQ(); - } darwinEvents_unlock(); + } input_unlock(); } void @@ -519,12 +491,6 @@ DarwinSendPointerEvents(DeviceIntPtr pDev, int ev_type, int ev_button, ScreenPtr screen; ValuatorMask valuators; - if (!darwinEvents) { - DEBUG_LOG("%s called before darwinEvents was initialized\n", - __FUNCTION__); - return; - } - screen = miPointerGetScreen(pDev); if (!screen) { DEBUG_LOG("%s called before screen was initialized\n", @@ -587,29 +553,22 @@ DarwinSendPointerEvents(DeviceIntPtr pDev, int ev_type, int ev_button, valuator_mask_set_double(&valuators, 3, pointer_dy); } - darwinEvents_lock(); + input_lock(); { QueuePointerEvents(pDev, ev_type, ev_button, POINTER_ABSOLUTE, &valuators); DarwinPokeEQ(); - } darwinEvents_unlock(); + } input_unlock(); } void DarwinSendKeyboardEvents(int ev_type, int keycode) { - - if (!darwinEvents) { - DEBUG_LOG( - "DarwinSendKeyboardEvents called before darwinEvents was initialized\n"); - return; - } - - darwinEvents_lock(); + input_lock(); { QueueKeyboardEvents(darwinKeyboard, ev_type, keycode + MIN_KEYCODE); DarwinPokeEQ(); - } darwinEvents_unlock(); + } input_unlock(); } /* Send the appropriate number of button clicks to emulate scroll wheel */ @@ -618,12 +577,6 @@ DarwinSendScrollEvents(double scroll_x, double scroll_y) { ScreenPtr screen; ValuatorMask valuators; - if (!darwinEvents) { - DEBUG_LOG( - "DarwinSendScrollEvents called before darwinEvents was initialized\n"); - return; - } - screen = miPointerGetScreen(darwinPointer); if (!screen) { DEBUG_LOG( @@ -635,12 +588,12 @@ DarwinSendScrollEvents(double scroll_x, double scroll_y) { valuator_mask_set_double(&valuators, 4, scroll_y); valuator_mask_set_double(&valuators, 5, scroll_x); - darwinEvents_lock(); + input_lock(); { QueuePointerEvents(darwinPointer, MotionNotify, 0, POINTER_RELATIVE, &valuators); DarwinPokeEQ(); - } darwinEvents_unlock(); + } input_unlock(); } /* Send the appropriate KeyPress/KeyRelease events to GetKeyboardEvents to @@ -682,9 +635,11 @@ DarwinSendDDXEvent(int type, int argc, ...) va_end(args); } - darwinEvents_lock(); + wait_for_mieq_init(); + + input_lock(); { mieqEnqueue(NULL, (InternalEvent *)&e); DarwinPokeEQ(); - } darwinEvents_unlock(); + } input_unlock(); } diff --git a/mi/mieq.c b/mi/mieq.c index e31e4f125..a6e867df6 100644 --- a/mi/mieq.c +++ b/mi/mieq.c @@ -87,24 +87,6 @@ typedef struct _EventQueue { static EventQueueRec miEventQueue; -#ifdef XQUARTZ -extern BOOL serverRunning; -extern pthread_mutex_t serverRunningMutex; -extern pthread_cond_t serverRunningCond; - -static inline void -wait_for_server_init(void) -{ - /* If the server hasn't finished initializing, wait for it... */ - if (!serverRunning) { - pthread_mutex_lock(&serverRunningMutex); - while (!serverRunning) - pthread_cond_wait(&serverRunningCond, &serverRunningMutex); - pthread_mutex_unlock(&serverRunningMutex); - } -} -#endif - static size_t mieqNumEnqueued(EventQueuePtr eventQueue) { @@ -219,10 +201,6 @@ mieqEnqueue(DeviceIntPtr pDev, InternalEvent *e) Time time; size_t n_enqueued; -#ifdef XQUARTZ - wait_for_server_init(); -#endif - verify_internal_event(e); n_enqueued = mieqNumEnqueued(&miEventQueue); diff --git a/mi/mipointer.c b/mi/mipointer.c index 01f3bd2fe..75be1aeeb 100644 --- a/mi/mipointer.c +++ b/mi/mipointer.c @@ -709,12 +709,6 @@ miPointerGetPosition(DeviceIntPtr pDev, int *x, int *y) *y = MIPOINTER(pDev)->y; } -#ifdef XQUARTZ -#include -void darwinEvents_lock(void); -void darwinEvents_unlock(void); -#endif - /** * Move the device's pointer to the x/y coordinates on the given screen. * This function generates and enqueues pointer events. @@ -752,13 +746,7 @@ miPointerMove(DeviceIntPtr pDev, ScreenPtr pScreen, int x, int y) POINTER_NORAW, &mask); input_lock(); -#ifdef XQUARTZ - darwinEvents_lock(); -#endif for (i = 0; i < nevents; i++) mieqEnqueue(pDev, &mipointermove_events[i]); -#ifdef XQUARTZ - darwinEvents_unlock(); -#endif input_unlock(); } diff --git a/test/ddxstubs.c b/test/ddxstubs.c index 3647dc556..58bc0c428 100644 --- a/test/ddxstubs.c +++ b/test/ddxstubs.c @@ -83,26 +83,10 @@ LegalModifier(unsigned int key, DeviceIntPtr pDev) } #ifdef XQUARTZ -#include - -BOOL serverRunning = TRUE; -pthread_mutex_t serverRunningMutex = PTHREAD_MUTEX_INITIALIZER; -pthread_cond_t serverRunningCond = PTHREAD_COND_INITIALIZER; - int darwinMainScreenX = 0; int darwinMainScreenY = 0; BOOL no_configure_window = FALSE; - -void -darwinEvents_lock(void) -{ -} - -void -darwinEvents_unlock(void) -{ -} #endif #ifdef DDXBEFORERESET