summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar emersion <contact@emersion.fr>2018-11-25 18:10:01 +0100
committerLibravatar emersion <contact@emersion.fr>2018-11-25 18:10:01 +0100
commit814dc1dfe5bbfa47a0cfbcfe2c7dd7119b0bad7e (patch)
treebdaaf06ed6def2e4f97128077eb5afa587b9d99c
parentMerge pull request #3184 from kupospelov/fix-resize (diff)
downloadsway-814dc1dfe5bbfa47a0cfbcfe2c7dd7119b0bad7e.tar.gz
sway-814dc1dfe5bbfa47a0cfbcfe2c7dd7119b0bad7e.tar.zst
sway-814dc1dfe5bbfa47a0cfbcfe2c7dd7119b0bad7e.zip
swayidle: fix busy loop on writable FD
The wl_event_source_fd_update docs say: > File descriptors are usually writable to begin with, so they do not need to > be polled for writable until a write actually fails. When a write fails, > the event mask can be changed to poll for readable and writable, delivering > a dispatch callback when it is possible to write more. Once all data has > been written, the mask can be changed to poll only for readable to avoid > busy-looping on dispatch. So we should only poll for WL_EVENT_WRITABLE if a write fails. I'm not yet sure how to do this properly and Weston doesn't do it, so in the meantime I'll just fix the busy loop. I'll ask them too. Fixes https://github.com/swaywm/sway/issues/3190
-rw-r--r--swayidle/main.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/swayidle/main.c b/swayidle/main.c
index 89ccf671..dd7d9de3 100644
--- a/swayidle/main.c
+++ b/swayidle/main.c
@@ -192,8 +192,7 @@ static void setup_sleep_listener(void) {
192 acquire_sleep_lock(); 192 acquire_sleep_lock();
193 193
194 struct wl_event_source *source = wl_event_loop_add_fd(state.event_loop, 194 struct wl_event_source *source = wl_event_loop_add_fd(state.event_loop,
195 sd_bus_get_fd(bus), WL_EVENT_READABLE | WL_EVENT_WRITABLE, 195 sd_bus_get_fd(bus), WL_EVENT_READABLE, dbus_event, bus);
196 dbus_event, bus);
197 wl_event_source_check(source); 196 wl_event_source_check(source);
198} 197}
199#endif 198#endif
@@ -401,10 +400,12 @@ static int display_event(int fd, uint32_t mask, void *data) {
401 count = wl_display_dispatch_pending(state.display); 400 count = wl_display_dispatch_pending(state.display);
402 wl_display_flush(state.display); 401 wl_display_flush(state.display);
403 } 402 }
403
404 if (count < 0) { 404 if (count < 0) {
405 wlr_log_errno(WLR_ERROR, "wl_display_dispatch failed, exiting"); 405 wlr_log_errno(WLR_ERROR, "wl_display_dispatch failed, exiting");
406 sway_terminate(0); 406 sway_terminate(0);
407 } 407 }
408
408 return count; 409 return count;
409} 410}
410 411
@@ -462,7 +463,7 @@ int main(int argc, char *argv[]) {
462 wl_display_roundtrip(state.display); 463 wl_display_roundtrip(state.display);
463 464
464 struct wl_event_source *source = wl_event_loop_add_fd(state.event_loop, 465 struct wl_event_source *source = wl_event_loop_add_fd(state.event_loop,
465 wl_display_get_fd(state.display), WL_EVENT_READABLE | WL_EVENT_WRITABLE, 466 wl_display_get_fd(state.display), WL_EVENT_READABLE,
466 display_event, NULL); 467 display_event, NULL);
467 wl_event_source_check(source); 468 wl_event_source_check(source);
468 469