[client] x11: switch to epoll for event wait loop

This commit is contained in:
Geoffrey McRae 2021-08-09 15:23:44 +10:00
parent f50ef4c23c
commit 179eaef29d

View file

@ -26,6 +26,7 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <sys/epoll.h>
#include <X11/extensions/XInput2.h> #include <X11/extensions/XInput2.h>
#include <X11/extensions/scrnsaver.h> #include <X11/extensions/scrnsaver.h>
@ -638,8 +639,21 @@ static bool x11GetProp(LG_DSProperty prop, void *ret)
static int x11EventThread(void * unused) static int x11EventThread(void * unused)
{ {
fd_set in_fds; int epollfd = epoll_create1(0);
if (epollfd == -1)
{
DEBUG_ERROR("epolld_create1 failure");
return 0;
}
struct epoll_event ev = { .events = EPOLLIN };
const int fd = ConnectionNumber(x11.display); const int fd = ConnectionNumber(x11.display);
if (epoll_ctl(epollfd, EPOLL_CTL_ADD, fd, &ev) == -1)
{
close(epollfd);
DEBUG_ERROR("epoll_ctl failed");
return 0;
}
while(app_isRunning()) while(app_isRunning())
{ {
@ -652,16 +666,16 @@ static int x11EventThread(void * unused)
if (!XPending(x11.display)) if (!XPending(x11.display))
{ {
FD_ZERO(&in_fds); struct epoll_event events[1];
FD_SET(fd, &in_fds); int nfds = epoll_wait(epollfd, events, 1, 100);
struct timeval tv = if (nfds == -1)
{ {
.tv_usec = 250000, close(epollfd);
.tv_sec = 0 DEBUG_ERROR("epoll_wait failure");
}; return 0;
}
int ret = select(fd + 1, &in_fds, NULL, NULL, &tv); if (nfds == 0)
if (ret == 0 || !XPending(x11.display))
continue; continue;
} }
@ -804,6 +818,7 @@ static int x11EventThread(void * unused)
} }
} }
close(epollfd);
return 0; return 0;
} }