答复: [PATCH] udev_monitor_receive_device() will block when hotplug monitor

Submitted by Qu, Jim on Dec. 13, 2016, 11:45 p.m.

Details

Message ID BY2PR12MB0614902C30ED5713060FBA48999B0@BY2PR12MB0614.namprd12.prod.outlook.com
State New
Headers show
Series "udev_monitor_receive_device() will block when hotplug monitor" ( rev: 2 ) in AMD X.Org drivers

Not browsing as part of any series.

Commit Message

Qu, Jim Dec. 13, 2016, 11:45 p.m.
ping.....

Thanks
JimQu

________________________________________
发件人: jimqu <Jim.Qu@amd.com>
发送时间: 2016年12月13日 16:33
收件人: amd-gfx@lists.freedesktop.org
抄送: Qu, Jim
主题: [PATCH] udev_monitor_receive_device() will block when hotplug monitor

udev_monitor_receive_device() will block and wait for the event of udev
use select() to ensure that this will not block.

Change-Id: I4e8f4629580222e94f55a4c03070741bf5f4024c
Signed-off-by: JimQu <Jim.Qu@amd.com>

---
 src/drmmode_display.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

--
1.9.1

Patch hide | download patch | download mbox

diff --git a/src/drmmode_display.c b/src/drmmode_display.c
index 79c9390..a5b4345 100644
--- a/src/drmmode_display.c
+++ b/src/drmmode_display.c
@@ -2528,10 +2528,26 @@  static void drmmode_handle_uevents(int fd, void *closure)
        ScrnInfoPtr scrn = drmmode->scrn;
        struct udev_device *dev;
        Bool received = FALSE;
+       struct timeval tv;
+       fd_set readfd;
+       int ret;
+
+       FD_ZERO(&readfd);
+       FD_SET(fd, &readfd);
+       tv.tv_sec = 0;
+       tv.tv_usec = 0;

-       while ((dev = udev_monitor_receive_device(drmmode->uevent_monitor))) {
-               udev_device_unref(dev);
-               received = TRUE;
+       while (1) {
+               ret = select(fd + 1, &readfd, NULL, NULL, &tv);
+               /* Check if our file descriptor has received data. */
+               if (!(ret > 0 && FD_ISSET(fd, &readfd)))
+                       break;
+               /* Make the call to receive device. select() ensured that this will not be blocked. */
+               dev = udev_monitor_receive_device(drmmode->uevent_monitor);
+               if (dev) {
+                       udev_device_unref(dev);
+                       received = TRUE;
+               }
        }

        if (received)