From 30ac7567980a1eb79d084a63e0e74e1d9a3af673 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 8 Dec 2015 11:37:51 -0800 Subject: Create a threaded mechanism for input [v7] The current SIGIO signal handler method, used at generation of input events, has a bunch of oddities. This patch introduces an alternative way using a thread, which is used to select() all input device file descriptors. A mutex was used to control the access to input structures by the main and input threads. Two pipes to emit alert events (such hotplug ones) and guarantee the proper communication between them was also used. Co-authored-by: Fernando Carrijo Signed-off-by: Tiago Vignatti v2: Fix non-Xorg link. Enable where supported by default. This also splits out the actual enabling of input threads to DDX-specific patches which follow v3: Make the input lock recursive v4: Use regular RECURSIVE_MUTEXes instead of rolling our own Respect the --disable-input-thread configuration option by providing stubs that expose the same API/ABI. Respond to style comments from Peter Hutterer. v5: use __func__ in inputthread debug and error mesages. Respond to style comments from Peter Hutterer. v6: use AX_PTHREAD instead of inlining pthread tests. Suggested by Emil Velikov v7: Use pthread_sigmask instead of sigprocmask when using threads Suggested by Adam Jackson Signed-off-by: Adam Jackson Signed-off-by: Keith Packard Reviewed-by: Adam Jackson --- mi/mieq.c | 38 ++++---------------------------------- 1 file changed, 4 insertions(+), 34 deletions(-) (limited to 'mi') diff --git a/mi/mieq.c b/mi/mieq.c index 8fbe6c363..8a6721304 100644 --- a/mi/mieq.c +++ b/mi/mieq.c @@ -88,9 +88,6 @@ typedef struct _EventQueue { static EventQueueRec miEventQueue; #ifdef XQUARTZ -#include -static pthread_mutex_t miEventQueueMutex = PTHREAD_MUTEX_INITIALIZER; - extern BOOL serverRunning; extern pthread_mutex_t serverRunningMutex; extern pthread_cond_t serverRunningCond; @@ -252,7 +249,6 @@ mieqEnqueue(DeviceIntPtr pDev, InternalEvent *e) #ifdef XQUARTZ wait_for_server_init(); - pthread_mutex_lock(&miEventQueueMutex); #endif verify_internal_event(e); @@ -296,9 +292,6 @@ mieqEnqueue(DeviceIntPtr pDev, InternalEvent *e) xorg_backtrace(); } -#ifdef XQUARTZ - pthread_mutex_unlock(&miEventQueueMutex); -#endif return; } @@ -319,9 +312,6 @@ mieqEnqueue(DeviceIntPtr pDev, InternalEvent *e) miEventQueue.lastMotion = isMotion; miEventQueue.tail = (oldtail + 1) % miEventQueue.nevents; -#ifdef XQUARTZ - pthread_mutex_unlock(&miEventQueueMutex); -#endif } /** @@ -342,31 +332,19 @@ mieqEnqueue(DeviceIntPtr pDev, InternalEvent *e) void mieqSwitchScreen(DeviceIntPtr pDev, ScreenPtr pScreen, Bool set_dequeue_screen) { -#ifdef XQUARTZ - pthread_mutex_lock(&miEventQueueMutex); -#endif EnqueueScreen(pDev) = pScreen; if (set_dequeue_screen) DequeueScreen(pDev) = 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("[mi] 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 } /** @@ -581,9 +559,7 @@ mieqProcessInputEvents(void) size_t n_enqueued; static Bool inProcessInputEvents = FALSE; -#ifdef XQUARTZ - pthread_mutex_lock(&miEventQueueMutex); -#endif + input_lock(); /* * report an error if mieqProcessInputEvents() is called recursively; @@ -621,9 +597,7 @@ mieqProcessInputEvents(void) miEventQueue.head = (miEventQueue.head + 1) % miEventQueue.nevents; -#ifdef XQUARTZ - pthread_mutex_unlock(&miEventQueueMutex); -#endif + input_unlock(); master = (dev) ? GetMaster(dev, MASTER_ATTACHED) : NULL; @@ -647,14 +621,10 @@ mieqProcessInputEvents(void) event.device_event.flags & TOUCH_POINTER_EMULATED))) miPointerUpdateSprite(dev); -#ifdef XQUARTZ - pthread_mutex_lock(&miEventQueueMutex); -#endif + input_lock(); } inProcessInputEvents = FALSE; -#ifdef XQUARTZ - pthread_mutex_unlock(&miEventQueueMutex); -#endif + input_unlock(); } -- cgit v1.2.3