[mutter/gnome-3-26] monitor-manager-kms: poll() on KMS fd on EAGAIN



commit 6dd28bd2c7e0ce32fa38b72a49007b9f5fe88272
Author: Benjamin Berg <bberg redhat com>
Date:   Wed Nov 29 21:23:29 2017 +0100

    monitor-manager-kms: poll() on KMS fd on EAGAIN
    
    When drmHandleEvent() returns an error and errno is set to EAGAIN,
    instead of ending up in a busy loop, poll() the fd until there is
    anything to read.
    
    This is a simple backport of commit 406359bba1.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=791024

 src/backends/native/meta-monitor-manager-kms.c |   30 +++++++++++++++++++++++-
 1 files changed, 29 insertions(+), 1 deletions(-)
---
diff --git a/src/backends/native/meta-monitor-manager-kms.c b/src/backends/native/meta-monitor-manager-kms.c
index cbd5209..32a8aa6 100644
--- a/src/backends/native/meta-monitor-manager-kms.c
+++ b/src/backends/native/meta-monitor-manager-kms.c
@@ -34,6 +34,7 @@
 
 #include <drm.h>
 #include <errno.h>
+#include <poll.h>
 #include <sys/ioctl.h>
 #include <sys/mman.h>
 #include <unistd.h>
@@ -1782,7 +1783,34 @@ meta_monitor_manager_kms_wait_for_flip (MetaMonitorManagerKms *manager_kms)
   memset (&evctx, 0, sizeof evctx);
   evctx.version = DRM_EVENT_CONTEXT_VERSION;
   evctx.page_flip_handler = page_flip_handler;
-  drmHandleEvent (manager_kms->fd, &evctx);
+
+  while (TRUE)
+    {
+      if (drmHandleEvent (manager_kms->fd, &evctx) != 0)
+        {
+          struct pollfd pfd;
+          int ret;
+
+          if (errno != EAGAIN)
+            {
+              g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+                                   strerror (errno));
+              return;
+            }
+
+          pfd.fd = manager_kms->fd;
+          pfd.events = POLL_IN | POLL_ERR;
+          do
+            {
+              ret = poll (&pfd, 1, -1);
+            }
+          while (ret == -1 && errno == EINTR);
+        }
+      else
+        {
+          break;
+        }
+    }
 }
 
 static gboolean


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]