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.
This commit is contained in:
parent
bbe7183cd3
commit
0c2a3054ba
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue