xserver: Branch 'master'

Peter Hutterer whot at kemper.freedesktop.org
Fri Aug 12 00:36:00 UTC 2016


 os/inputthread.c |   36 +++++++++++++++++++++++++-----------
 1 file changed, 25 insertions(+), 11 deletions(-)

New commits:
commit bf31d6f43e5ce04891a96b226a975379e2e2ba71
Author: Keith Packard <keithp at keithp.com>
Date:   Thu Aug 11 12:34:54 2016 -0700

    os: Allow re-registering fd with InputThreadRegisterDev
    
    Calling InputThreadRegisterDev twice with the same fd should replace
    the existing function and args instead of creating a new entry with
    the same fd.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/os/inputthread.c b/os/inputthread.c
index cb3af06..1cd1c2a 100644
--- a/os/inputthread.c
+++ b/os/inputthread.c
@@ -188,24 +188,38 @@ InputThreadRegisterDev(int fd,
                        NotifyFdProcPtr readInputProc,
                        void *readInputArgs)
 {
-    InputThreadDevice *dev;
+    InputThreadDevice *dev, *old;
 
     if (!inputThreadInfo)
         return SetNotifyFd(fd, readInputProc, X_NOTIFY_READ, readInputArgs);
 
-    dev = calloc(1, sizeof(InputThreadDevice));
-    if (dev == NULL) {
-        DebugF("input-thread: could not register device\n");
-        return 0;
+    input_lock();
+
+    dev = NULL;
+    xorg_list_for_each_entry(old, &inputThreadInfo->devs, node) {
+        if (old->fd == fd) {
+            dev = old;
+            break;
+        }
     }
 
-    dev->fd = fd;
-    dev->readInputProc = readInputProc;
-    dev->readInputArgs = readInputArgs;
-    dev->state = device_state_added;
+    if (dev) {
+        dev->readInputProc = readInputProc;
+        dev->readInputArgs = readInputArgs;
+    } else {
+        dev = calloc(1, sizeof(InputThreadDevice));
+        if (dev == NULL) {
+            DebugF("input-thread: could not register device\n");
+            input_unlock();
+            return 0;
+        }
 
-    input_lock();
-    xorg_list_append(&dev->node, &inputThreadInfo->devs);
+        dev->fd = fd;
+        dev->readInputProc = readInputProc;
+        dev->readInputArgs = readInputArgs;
+        dev->state = device_state_added;
+        xorg_list_append(&dev->node, &inputThreadInfo->devs);
+    }
 
     inputThreadInfo->changed = TRUE;
 


More information about the xorg-commit mailing list