AMD-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] udev_monitor_receive_device() will block when hotplug monitor
@ 2016-12-13  8:33 jimqu
       [not found] ` <1481618006-29239-1-git-send-email-Jim.Qu-5C7GfCeVMHo@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: jimqu @ 2016-12-13  8:33 UTC (permalink / raw)
  To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW; +Cc: 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
Signed-off-by: JimQu <Jim.Qu@amd.com>
---
 src/drmmode_display.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

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)
-- 
1.9.1

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* 答复: [PATCH] udev_monitor_receive_device() will block when hotplug monitor
       [not found] ` <1481618006-29239-1-git-send-email-Jim.Qu-5C7GfCeVMHo@public.gmane.org>
@ 2016-12-13 23:45   ` Qu, Jim
  2016-12-14  3:03   ` Michel Dänzer
  1 sibling, 0 replies; 4+ messages in thread
From: Qu, Jim @ 2016-12-13 23:45 UTC (permalink / raw)
  To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org

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(-)

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)
--
1.9.1

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] udev_monitor_receive_device() will block when hotplug monitor
       [not found] ` <1481618006-29239-1-git-send-email-Jim.Qu-5C7GfCeVMHo@public.gmane.org>
  2016-12-13 23:45   ` 答复: " Qu, Jim
@ 2016-12-14  3:03   ` Michel Dänzer
       [not found]     ` <056cefae-e2c6-7cd7-c7fd-461e1cb8bf25-otUistvHUpPR7s880joybQ@public.gmane.org>
  1 sibling, 1 reply; 4+ messages in thread
From: Michel Dänzer @ 2016-12-14  3:03 UTC (permalink / raw)
  To: jimqu; +Cc: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

On 13/12/16 05:33 PM, jimqu wrote:
> 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>

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
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 4+ messages in thread

* 答复: [PATCH] udev_monitor_receive_device() will block when hotplug monitor
       [not found]     ` <056cefae-e2c6-7cd7-c7fd-461e1cb8bf25-otUistvHUpPR7s880joybQ@public.gmane.org>
@ 2016-12-14  3:33       ` Qu, Jim
  0 siblings, 0 replies; 4+ messages in thread
From: Qu, Jim @ 2016-12-14  3:33 UTC (permalink / raw)
  To: Michel Dänzer
  Cc: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org

Got it!

Thanks
JimQu

________________________________________
发件人: Michel Dänzer <michel@daenzer.net>
发送时间: 2016年12月14日 11:03
收件人: Qu, Jim
抄送: amd-gfx@lists.freedesktop.org
主题: Re: [PATCH] udev_monitor_receive_device() will block when hotplug monitor

On 13/12/16 05:33 PM, jimqu wrote:
> 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>

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
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-12-14  3:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-12-13  8:33 [PATCH] udev_monitor_receive_device() will block when hotplug monitor jimqu
     [not found] ` <1481618006-29239-1-git-send-email-Jim.Qu-5C7GfCeVMHo@public.gmane.org>
2016-12-13 23:45   ` 答复: " Qu, Jim
2016-12-14  3:03   ` Michel Dänzer
     [not found]     ` <056cefae-e2c6-7cd7-c7fd-461e1cb8bf25-otUistvHUpPR7s880joybQ@public.gmane.org>
2016-12-14  3:33       ` 答复: " Qu, Jim

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox