From f9fcb7d737f9be5b80b4457e4ee22952e31e3d0f Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Wed, 11 May 2011 18:21:25 +1000 Subject: [PATCH] xfree86/linux: use F_SETOWN_EX to send SIGIO to main thread --- hw/xfree86/os-support/shared/sigio.c | 33 ++++++++++++++++++++++++++++----- 1 files changed, 28 insertions(+), 5 deletions(-) diff --git a/hw/xfree86/os-support/shared/sigio.c b/hw/xfree86/os-support/shared/sigio.c index 274a8ab..780cc11 100644 --- a/hw/xfree86/os-support/shared/sigio.c +++ b/hw/xfree86/os-support/shared/sigio.c @@ -66,6 +66,13 @@ # include #endif +#ifdef F_SETOWN_EX +#include +static pid_t gettid(void) +{ + return (pid_t)syscall(__NR_gettid); +} +#endif #ifdef MAXDEVICES /* MAXDEVICES represents the maximimum number of input devices usable * at the same time plus one entry for DRM support. @@ -151,12 +158,28 @@ xf86InstallSIGIOHandler(int fd, void (*f)(int, void *), void *closure) xf86Msg(X_WARNING, "fcntl(%d, O_ASYNC): %s\n", fd, strerror(errno)); } else { - if (fcntl(fd, F_SETOWN, getpid()) == -1) { - xf86Msg(X_WARNING, "fcntl(%d, F_SETOWN): %s\n", - fd, strerror(errno)); - } else { - installed = TRUE; + int own_res = -1; +#ifdef F_SETOWN_EX + { + struct f_owner_ex f_ex; + f_ex.type = F_OWNER_TID; + f_ex.pid = gettid(); + own_res = fcntl(fd, F_SETOWN_EX, &f_ex); + if (own_res == -1) { + xf86Msg(X_WARNING, "fcntl(%d, F_SETOWN_EX): %s\n", + fd, strerror(errno)); + } + } +#endif + if (own_res == -1) { + own_res = fcntl(fd, F_SETOWN, getpid()); + if (own_res == -1) { + xf86Msg(X_WARNING, "fcntl(%d, F_SETOWN): %s\n", + fd, strerror(errno)); + } } + if (own_res == 0) + installed = TRUE; } #endif #ifdef I_SETSIG /* System V Streams - used on Solaris for input devices */ -- 1.7.4.4