Skip to contentSkip to conversation

udev_monitor_receive_device() will block when hotplug monitor

PATCH In review jimqu 2 participants 4 messages Dec 13, 2016 – Dec 14, 2016 2 messages not in the archive

lore
Share & tools
lore

jimqu

author
#0 lore raw

PATCH 1/1 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
---
 src/drmmode_display.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)
src/drmmode_display.c +19 -3
index 79c9390..a5b4345 100644
@@ -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)
Signature · 6 lines
1.9.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 1481618006-29239-1-git-send-email-Jim.Qu-5C7GfCeVMHo@public.gmane.org

author
#2 lore raw

ping.....

Thanks
JimQu

________________________________________
发件人: jimqu <[email protected]>
发送时间: 2016年12月13日 16:33
收件人: [email protected]
抄送: 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
---
 src/drmmode_display.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)
src/drmmode_display.c +19 -3
index 79c9390..a5b4345 100644
@@ -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)

--
1.9.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#3 lore raw
In reply to a message not in the archive
Quoted 5 lines · jimqu

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

Reviewed and pushed, thanks!

P.S. Please run

git config --global user.name "Jim Qu"
git config email.prefix "PATCH $(basename $PWD)"

in your Git tree.

Signature · 6 lines
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 056cefae-e2c6-7cd7-c7fd-461e1cb8bf25-otUistvHUpPR7s880joybQ@public.gmane.org

author
#5 lore raw

Got it!

Thanks
JimQu

________________________________________
发件人: Michel Dänzer <[email protected]>
发送时间: 2016年12月14日 11:03
收件人: Qu, Jim
抄送: [email protected]
主题: Re: [PATCH] udev_monitor_receive_device() will block when hotplug monitor

Quoted 5 lines · jimqu

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

Reviewed and pushed, thanks!

P.S. Please run

git config --global user.name "Jim Qu"
git config email.prefix "PATCH $(basename $PWD)"

in your Git tree.

--
Earthling Michel Dänzer | http://www.amd.com
Libre software enthusiast | Mesa and X developer
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx