Skip to content

fix: resolve high CPU busy-loop in event loop - #91

Merged
vaxerski merged 1 commit into
hyprwm:mainfrom
TakenCC:fix-eventloop-cpu-loop
Jun 30, 2026
Merged

fix: resolve high CPU busy-loop in event loop#91
vaxerski merged 1 commit into
hyprwm:mainfrom
TakenCC:fix-eventloop-cpu-loop

Conversation

@TakenCC

@TakenCC TakenCC commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

This pull request resolves a high CPU busy-loop condition in hyprsunset's Wayland event loop.

Cause

When wl_display_prepare_read() fails (returns -1, e.g. due to pending events in the queue), preparedToRead is set to false. In this case, pollThread skips calling poll() but still triggers a wakeup to the event loop thread (shouldProcess = true).
However, the event loop thread only calls wl_display_dispatch_pending() if pollfds[0].revents & POLLIN is set. Since poll() was skipped, pollfds[0].revents is not updated and does not have the POLLIN flag set. As a result, the pending events are never dispatched, wl_display_prepare_read() continues to fail, and the program enters an infinite tight loop consuming 100% CPU.

Fix

Introduce a synchronized boolean wlEventsPending which is set to true whenever wl_display_prepare_read() fails (meaning events are ready to be dispatched) or pollfds[0].revents & POLLIN is set. The main loop checks this flag to determine when to call wl_display_dispatch_pending() and wl_display_flush().

@vaxerski vaxerski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tnx

@vaxerski
vaxerski merged commit 5eac3a9 into hyprwm:main Jun 30, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants