Switch to poll
epoll doesn't offer any benefit for our use-case. select is old. Let's just make things consistent and use the portable poll everywhere.
This commit is contained in:
parent
9a6b72f712
commit
5fedd45d2f
2 changed files with 33 additions and 44 deletions
24
src/drm.cpp
24
src/drm.cpp
|
@ -10,7 +10,7 @@
|
|||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/select.h>
|
||||
#include <poll.h>
|
||||
|
||||
extern "C" {
|
||||
#include <wlr/types/wlr_buffer.h>
|
||||
|
@ -270,23 +270,23 @@ static void page_flip_handler(int fd, unsigned int frame,
|
|||
|
||||
void flip_handler_thread_run(void)
|
||||
{
|
||||
fd_set fds;
|
||||
int ret;
|
||||
drmEventContext evctx = {
|
||||
.version = 2,
|
||||
.page_flip_handler = page_flip_handler,
|
||||
struct pollfd pollfd = {
|
||||
.fd = g_DRM.fd,
|
||||
.events = POLLIN,
|
||||
};
|
||||
|
||||
FD_ZERO(&fds);
|
||||
FD_SET(0, &fds);
|
||||
FD_SET(g_DRM.fd, &fds);
|
||||
|
||||
while ( true )
|
||||
{
|
||||
ret = select(g_DRM.fd + 1, &fds, NULL, NULL, NULL);
|
||||
if (ret < 0) {
|
||||
int ret = poll( &pollfd, 1, -1 );
|
||||
if ( ret < 0 ) {
|
||||
perror( "drm: polling for DRM events failed" );
|
||||
break;
|
||||
}
|
||||
|
||||
drmEventContext evctx = {
|
||||
.version = 2,
|
||||
.page_flip_handler = page_flip_handler,
|
||||
};
|
||||
drmHandleEvent(g_DRM.fd, &evctx);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <poll.h>
|
||||
|
||||
#include <map>
|
||||
|
||||
|
@ -613,47 +613,36 @@ void wlserver_unlock(void)
|
|||
|
||||
int wlserver_run(void)
|
||||
{
|
||||
int epoll_fd = epoll_create( 1 );
|
||||
struct epoll_event ev;
|
||||
struct epoll_event events[128];
|
||||
int n;
|
||||
|
||||
ev.events = EPOLLIN;
|
||||
|
||||
if ( epoll_fd == -1 ||
|
||||
epoll_ctl( epoll_fd, EPOLL_CTL_ADD, wlserver.wl_event_loop_fd, &ev ) == -1 )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
while ( run )
|
||||
{
|
||||
n = epoll_wait( epoll_fd, events, 128, -1 );
|
||||
if ( n == -1 )
|
||||
{
|
||||
struct pollfd pollfd = {
|
||||
.fd = wlserver.wl_event_loop_fd,
|
||||
.events = POLLIN,
|
||||
};
|
||||
while ( run ) {
|
||||
int ret = poll( &pollfd, 1, -1 );
|
||||
if ( ret < 0 ) {
|
||||
if ( errno == EINTR )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
perror( "wlserver: poll failed" );
|
||||
break;
|
||||
}
|
||||
|
||||
// We have wayland stuff to do, do it while locked
|
||||
wlserver_lock();
|
||||
|
||||
for ( int i = 0; i < n; i++ )
|
||||
{
|
||||
if ( pollfd.revents & (POLLHUP | POLLERR) ) {
|
||||
fprintf( stderr, "wlserver: socket %s\n", ( pollfd.revents & POLLERR ) ? "error" : "closed" );
|
||||
break;
|
||||
}
|
||||
|
||||
if ( pollfd.revents & POLLIN ) {
|
||||
// We have wayland stuff to do, do it while locked
|
||||
wlserver_lock();
|
||||
|
||||
wl_display_flush_clients(wlserver.wl_display);
|
||||
int ret = wl_event_loop_dispatch(wlserver.wl_event_loop, 0);
|
||||
if (ret < 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
wlserver_unlock();
|
||||
wlserver_unlock();
|
||||
}
|
||||
}
|
||||
|
||||
// We need to shutdown Xwayland before disconnecting all clients, otherwise
|
||||
|
|
Loading…
Reference in a new issue