#define AL_LOG_SECTION "poll" #include #include #include "poll_common.h" #ifdef STELA_POLL_INLINE bool stl_poll_common(struct stl_window *window, struct nn_pollfd *fds, bool block) { fds[0].revents = 0; #ifdef STELA_PAUSE fds[1].revents = 0; #endif #ifdef STELA_PAUSE if (nn_poll_fds(fds, 2, (block) ? -1 : 0) < 0 && errno != EINTR) { #else if (nn_poll_fds(fds, 1, (block) ? -1 : 0) < 0 && errno != EINTR) { #endif log_error("poll() failed %s (%d).", nn_strerror(errno), errno); return false; } // On Wayland this will happen consistantly if the program is lagging too hard. // https://github.com/swaywm/sway/commit/e3f0ba4cd9ca709cac115ade54958885614d889c if (fds[0].revents & (POLLERR | POLLHUP | POLLNVAL)) { // Fatal error. log_error("poll() returned error in revents (%d).", fds[0].revents); al_assert(false); exit(0); return false; } return !window->closed; } #ifdef STELA_PAUSE // wake() must be thread-safe. void stl_wake_common(struct nn_pollfd *fds) { s64 val = 1; ssize_t ret = nn_write(fds[1].fd, &val, sizeof(s64)); al_assert(ret == sizeof(s64)); } #endif #endif bool stl_process_events_common(struct stl_window *window, struct nn_pollfd *fds) { #ifdef STELA_POLL_INLINE #ifdef STELA_PAUSE if (fds[1].revents & POLLIN) { s64 val; ssize_t ret = nn_read(fds[1].fd, &val, sizeof(s64)); al_assert(ret == sizeof(s64)); window->pending_refresh = true; } #endif return (fds[0].revents & POLLIN); #else (void)fds; #endif return true; }