Commit: 0c2a3054ba92494fb1a63ceea3bf441093fd5b03
Author: Campbell Barton
Date:   Fri Jan 13 17:48:52 2023 +1100
Branches: master
https://developer.blender.org/rB0c2a3054ba92494fb1a63ceea3bf441093fd5b03

Fix high CPU use when idle under Wayland

Recently the event handling thread for Wayland sometimes used 100% of a
CPU core while idle.

Resolve by waiting for changes to the Wayland file-handle when
there are no events to read.

===================================================================

M       intern/ghost/intern/GHOST_SystemWayland.cpp

===================================================================

diff --git a/intern/ghost/intern/GHOST_SystemWayland.cpp 
b/intern/ghost/intern/GHOST_SystemWayland.cpp
index ef8ccd66685..d9e5b0c4e9d 100644
--- a/intern/ghost/intern/GHOST_SystemWayland.cpp
+++ b/intern/ghost/intern/GHOST_SystemWayland.cpp
@@ -1662,15 +1662,23 @@ static int 
ghost_wl_display_event_pump_from_thread(struct wl_display *wl_display
   server_mutex->lock();
   int err = 0;
   if (wl_display_prepare_read(wl_display) == 0) {
+    bool wait_on_fd = false;
     /* Use #GWL_IOR_NO_RETRY to ensure #SIGINT will break us out of our wait. 
*/
     if (file_descriptor_is_io_ready(fd, GWL_IOR_READ | GWL_IOR_NO_RETRY, 0) > 
0) {
       err = wl_display_read_events(wl_display);
     }
     else {
       wl_display_cancel_read(wl_display);
+      /* Without this, the thread will loop continuously, 100% CPU. */
+      wait_on_fd = true;
     }
 
     server_mutex->unlock();
+
+    if (wait_on_fd) {
+      /* Important this runs after unlocking. */
+      file_descriptor_is_io_ready(fd, GWL_IOR_READ | GWL_IOR_NO_RETRY, 
INT32_MAX);
+    }
   }
   else {
     server_mutex->unlock();

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to