XQuartz: Adopt input_lock() and input_unlock()
This allows us to remove darwinEvents_lock() and darwinEvents_unlock() and remove the serverRunning hack from dix Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
This commit is contained in:
parent
8bc4727f47
commit
7d6ebf3f4e
21
dix/main.c
21
dix/main.c
|
@ -120,12 +120,6 @@ Equipment Corporation.
|
||||||
|
|
||||||
extern void Dispatch(void);
|
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;
|
CallbackListPtr RootWindowFinalizeCallback = NULL;
|
||||||
|
|
||||||
int
|
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();
|
NotifyParentProcess();
|
||||||
|
|
||||||
InputThreadInit();
|
InputThreadInit();
|
||||||
|
|
||||||
Dispatch();
|
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();
|
UndisplayDevices();
|
||||||
DisableAllDevices();
|
DisableAllDevices();
|
||||||
|
|
||||||
|
|
|
@ -1311,9 +1311,7 @@ untrusted_str(NSEvent *e)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern void
|
extern void
|
||||||
darwinEvents_lock(void);
|
wait_for_mieq_init(void);
|
||||||
extern void
|
|
||||||
darwinEvents_unlock(void);
|
|
||||||
|
|
||||||
- (void) sendX11NSEvent:(NSEvent *)e
|
- (void) sendX11NSEvent:(NSEvent *)e
|
||||||
{
|
{
|
||||||
|
@ -1329,8 +1327,7 @@ darwinEvents_unlock(void);
|
||||||
|
|
||||||
if (!darwinTabletCurrent) {
|
if (!darwinTabletCurrent) {
|
||||||
/* Ensure that the event system is initialized */
|
/* Ensure that the event system is initialized */
|
||||||
darwinEvents_lock();
|
wait_for_mieq_init();
|
||||||
darwinEvents_unlock();
|
|
||||||
assert(darwinTabletStylus);
|
assert(darwinTabletStylus);
|
||||||
|
|
||||||
tilt = NSZeroPoint;
|
tilt = NSZeroPoint;
|
||||||
|
|
|
@ -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_cond_t fd_add_ready_cond = PTHREAD_COND_INITIALIZER;
|
||||||
static pthread_t fd_add_tid = NULL;
|
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;
|
extern inline void
|
||||||
static pthread_cond_t mieq_ready_cond = PTHREAD_COND_INITIALIZER;
|
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 ***/
|
/*** Pthread Magics ***/
|
||||||
static pthread_t
|
static pthread_t
|
||||||
|
@ -113,35 +133,6 @@ create_thread(void *(*func)(void *), void *arg)
|
||||||
return tid;
|
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
|
* DarwinPressModifierKey
|
||||||
* Press or release the given modifier key (one of NX_MODIFIERKEY_* constants)
|
* Press or release the given modifier key (one of NX_MODIFIERKEY_* constants)
|
||||||
|
@ -379,24 +370,11 @@ DarwinEQInit(void)
|
||||||
mieqInit();
|
mieqInit();
|
||||||
mieqSetHandler(ET_XQuartz, DarwinEventHandler);
|
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)
|
if (!fd_add_tid)
|
||||||
fd_add_tid = create_thread(DarwinProcessFDAdditionQueue_thread, NULL);
|
fd_add_tid = create_thread(DarwinProcessFDAdditionQueue_thread, NULL);
|
||||||
|
|
||||||
|
signal_mieq_init();
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -437,7 +415,7 @@ DarwinPokeEQ(void)
|
||||||
void
|
void
|
||||||
DarwinInputReleaseButtonsAndKeys(DeviceIntPtr pDev)
|
DarwinInputReleaseButtonsAndKeys(DeviceIntPtr pDev)
|
||||||
{
|
{
|
||||||
darwinEvents_lock();
|
input_lock();
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
if (pDev->button) {
|
if (pDev->button) {
|
||||||
|
@ -458,7 +436,7 @@ DarwinInputReleaseButtonsAndKeys(DeviceIntPtr pDev)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DarwinPokeEQ();
|
DarwinPokeEQ();
|
||||||
} darwinEvents_unlock();
|
} input_unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -470,12 +448,6 @@ DarwinSendTabletEvents(DeviceIntPtr pDev, int ev_type, int ev_button,
|
||||||
ScreenPtr screen;
|
ScreenPtr screen;
|
||||||
ValuatorMask valuators;
|
ValuatorMask valuators;
|
||||||
|
|
||||||
if (!darwinEvents) {
|
|
||||||
DEBUG_LOG("%s called before darwinEvents was initialized\n",
|
|
||||||
__FUNCTION__);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
screen = miPointerGetScreen(pDev);
|
screen = miPointerGetScreen(pDev);
|
||||||
if (!screen) {
|
if (!screen) {
|
||||||
DEBUG_LOG("%s called before screen was initialized\n",
|
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, 3, XQUARTZ_VALUATOR_LIMIT * tilt_x);
|
||||||
valuator_mask_set_double(&valuators, 4, XQUARTZ_VALUATOR_LIMIT * tilt_y);
|
valuator_mask_set_double(&valuators, 4, XQUARTZ_VALUATOR_LIMIT * tilt_y);
|
||||||
|
|
||||||
darwinEvents_lock();
|
input_lock();
|
||||||
{
|
{
|
||||||
if (ev_type == ProximityIn || ev_type == ProximityOut) {
|
if (ev_type == ProximityIn || ev_type == ProximityOut) {
|
||||||
QueueProximityEvents(pDev, ev_type, &valuators);
|
QueueProximityEvents(pDev, ev_type, &valuators);
|
||||||
|
@ -507,7 +479,7 @@ DarwinSendTabletEvents(DeviceIntPtr pDev, int ev_type, int ev_button,
|
||||||
&valuators);
|
&valuators);
|
||||||
}
|
}
|
||||||
DarwinPokeEQ();
|
DarwinPokeEQ();
|
||||||
} darwinEvents_unlock();
|
} input_unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -519,12 +491,6 @@ DarwinSendPointerEvents(DeviceIntPtr pDev, int ev_type, int ev_button,
|
||||||
ScreenPtr screen;
|
ScreenPtr screen;
|
||||||
ValuatorMask valuators;
|
ValuatorMask valuators;
|
||||||
|
|
||||||
if (!darwinEvents) {
|
|
||||||
DEBUG_LOG("%s called before darwinEvents was initialized\n",
|
|
||||||
__FUNCTION__);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
screen = miPointerGetScreen(pDev);
|
screen = miPointerGetScreen(pDev);
|
||||||
if (!screen) {
|
if (!screen) {
|
||||||
DEBUG_LOG("%s called before screen was initialized\n",
|
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);
|
valuator_mask_set_double(&valuators, 3, pointer_dy);
|
||||||
}
|
}
|
||||||
|
|
||||||
darwinEvents_lock();
|
input_lock();
|
||||||
{
|
{
|
||||||
QueuePointerEvents(pDev, ev_type, ev_button, POINTER_ABSOLUTE,
|
QueuePointerEvents(pDev, ev_type, ev_button, POINTER_ABSOLUTE,
|
||||||
&valuators);
|
&valuators);
|
||||||
DarwinPokeEQ();
|
DarwinPokeEQ();
|
||||||
} darwinEvents_unlock();
|
} input_unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
DarwinSendKeyboardEvents(int ev_type, int keycode)
|
DarwinSendKeyboardEvents(int ev_type, int keycode)
|
||||||
{
|
{
|
||||||
|
input_lock();
|
||||||
if (!darwinEvents) {
|
|
||||||
DEBUG_LOG(
|
|
||||||
"DarwinSendKeyboardEvents called before darwinEvents was initialized\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
darwinEvents_lock();
|
|
||||||
{
|
{
|
||||||
QueueKeyboardEvents(darwinKeyboard, ev_type, keycode + MIN_KEYCODE);
|
QueueKeyboardEvents(darwinKeyboard, ev_type, keycode + MIN_KEYCODE);
|
||||||
DarwinPokeEQ();
|
DarwinPokeEQ();
|
||||||
} darwinEvents_unlock();
|
} input_unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Send the appropriate number of button clicks to emulate scroll wheel */
|
/* Send the appropriate number of button clicks to emulate scroll wheel */
|
||||||
|
@ -618,12 +577,6 @@ DarwinSendScrollEvents(double scroll_x, double scroll_y) {
|
||||||
ScreenPtr screen;
|
ScreenPtr screen;
|
||||||
ValuatorMask valuators;
|
ValuatorMask valuators;
|
||||||
|
|
||||||
if (!darwinEvents) {
|
|
||||||
DEBUG_LOG(
|
|
||||||
"DarwinSendScrollEvents called before darwinEvents was initialized\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
screen = miPointerGetScreen(darwinPointer);
|
screen = miPointerGetScreen(darwinPointer);
|
||||||
if (!screen) {
|
if (!screen) {
|
||||||
DEBUG_LOG(
|
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, 4, scroll_y);
|
||||||
valuator_mask_set_double(&valuators, 5, scroll_x);
|
valuator_mask_set_double(&valuators, 5, scroll_x);
|
||||||
|
|
||||||
darwinEvents_lock();
|
input_lock();
|
||||||
{
|
{
|
||||||
QueuePointerEvents(darwinPointer, MotionNotify, 0,
|
QueuePointerEvents(darwinPointer, MotionNotify, 0,
|
||||||
POINTER_RELATIVE, &valuators);
|
POINTER_RELATIVE, &valuators);
|
||||||
DarwinPokeEQ();
|
DarwinPokeEQ();
|
||||||
} darwinEvents_unlock();
|
} input_unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Send the appropriate KeyPress/KeyRelease events to GetKeyboardEvents to
|
/* Send the appropriate KeyPress/KeyRelease events to GetKeyboardEvents to
|
||||||
|
@ -682,9 +635,11 @@ DarwinSendDDXEvent(int type, int argc, ...)
|
||||||
va_end(args);
|
va_end(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
darwinEvents_lock();
|
wait_for_mieq_init();
|
||||||
|
|
||||||
|
input_lock();
|
||||||
{
|
{
|
||||||
mieqEnqueue(NULL, (InternalEvent *)&e);
|
mieqEnqueue(NULL, (InternalEvent *)&e);
|
||||||
DarwinPokeEQ();
|
DarwinPokeEQ();
|
||||||
} darwinEvents_unlock();
|
} input_unlock();
|
||||||
}
|
}
|
||||||
|
|
22
mi/mieq.c
22
mi/mieq.c
|
@ -87,24 +87,6 @@ typedef struct _EventQueue {
|
||||||
|
|
||||||
static EventQueueRec miEventQueue;
|
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
|
static size_t
|
||||||
mieqNumEnqueued(EventQueuePtr eventQueue)
|
mieqNumEnqueued(EventQueuePtr eventQueue)
|
||||||
{
|
{
|
||||||
|
@ -219,10 +201,6 @@ mieqEnqueue(DeviceIntPtr pDev, InternalEvent *e)
|
||||||
Time time;
|
Time time;
|
||||||
size_t n_enqueued;
|
size_t n_enqueued;
|
||||||
|
|
||||||
#ifdef XQUARTZ
|
|
||||||
wait_for_server_init();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
verify_internal_event(e);
|
verify_internal_event(e);
|
||||||
|
|
||||||
n_enqueued = mieqNumEnqueued(&miEventQueue);
|
n_enqueued = mieqNumEnqueued(&miEventQueue);
|
||||||
|
|
|
@ -709,12 +709,6 @@ miPointerGetPosition(DeviceIntPtr pDev, int *x, int *y)
|
||||||
*y = MIPOINTER(pDev)->y;
|
*y = MIPOINTER(pDev)->y;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef XQUARTZ
|
|
||||||
#include <pthread.h>
|
|
||||||
void darwinEvents_lock(void);
|
|
||||||
void darwinEvents_unlock(void);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move the device's pointer to the x/y coordinates on the given screen.
|
* Move the device's pointer to the x/y coordinates on the given screen.
|
||||||
* This function generates and enqueues pointer events.
|
* This function generates and enqueues pointer events.
|
||||||
|
@ -752,13 +746,7 @@ miPointerMove(DeviceIntPtr pDev, ScreenPtr pScreen, int x, int y)
|
||||||
POINTER_NORAW, &mask);
|
POINTER_NORAW, &mask);
|
||||||
|
|
||||||
input_lock();
|
input_lock();
|
||||||
#ifdef XQUARTZ
|
|
||||||
darwinEvents_lock();
|
|
||||||
#endif
|
|
||||||
for (i = 0; i < nevents; i++)
|
for (i = 0; i < nevents; i++)
|
||||||
mieqEnqueue(pDev, &mipointermove_events[i]);
|
mieqEnqueue(pDev, &mipointermove_events[i]);
|
||||||
#ifdef XQUARTZ
|
|
||||||
darwinEvents_unlock();
|
|
||||||
#endif
|
|
||||||
input_unlock();
|
input_unlock();
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,26 +83,10 @@ LegalModifier(unsigned int key, DeviceIntPtr pDev)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef XQUARTZ
|
#ifdef XQUARTZ
|
||||||
#include <pthread.h>
|
|
||||||
|
|
||||||
BOOL serverRunning = TRUE;
|
|
||||||
pthread_mutex_t serverRunningMutex = PTHREAD_MUTEX_INITIALIZER;
|
|
||||||
pthread_cond_t serverRunningCond = PTHREAD_COND_INITIALIZER;
|
|
||||||
|
|
||||||
int darwinMainScreenX = 0;
|
int darwinMainScreenX = 0;
|
||||||
int darwinMainScreenY = 0;
|
int darwinMainScreenY = 0;
|
||||||
|
|
||||||
BOOL no_configure_window = FALSE;
|
BOOL no_configure_window = FALSE;
|
||||||
|
|
||||||
void
|
|
||||||
darwinEvents_lock(void)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
darwinEvents_unlock(void)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef DDXBEFORERESET
|
#ifdef DDXBEFORERESET
|
||||||
|
|
Loading…
Reference in New Issue
Block a user