mirror of
https://github.com/libretro/RetroArch
synced 2025-02-19 12:41:00 +00:00
Direct usage of epoll
This commit is contained in:
parent
e92feb85af
commit
a41b8bc199
@ -119,7 +119,6 @@ ifneq ($(findstring Linux,$(OS)),)
|
||||
LIBS += -lrt
|
||||
OBJ += input/drivers/linuxraw_input.o \
|
||||
input/common/linux_common.o \
|
||||
input/common/epoll_common.o \
|
||||
input/drivers_joypad/linuxraw_joypad.o \
|
||||
frontend/drivers/platform_linux.o
|
||||
endif
|
||||
|
@ -484,7 +484,6 @@ INPUT
|
||||
|
||||
#if defined(__linux__) && !defined(ANDROID)
|
||||
#include "../input/common/linux_common.c"
|
||||
#include "../input/common/epoll_common.c"
|
||||
#include "../input/drivers/linuxraw_input.c"
|
||||
#include "../input/drivers_joypad/linuxraw_joypad.c"
|
||||
#endif
|
||||
|
@ -1,56 +0,0 @@
|
||||
/* RetroArch - A frontend for libretro.
|
||||
* Copyright (C) 2013-2014 - pinumbernumber
|
||||
* Copyright (C) 2011-2017 - Daniel De Matteis
|
||||
*
|
||||
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Found-
|
||||
* ation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with RetroArch.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sys/epoll.h>
|
||||
|
||||
#include "epoll_common.h"
|
||||
|
||||
bool epoll_new(int *epoll_fd)
|
||||
{
|
||||
*epoll_fd = epoll_create(32);
|
||||
if (*epoll_fd < 0)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void epoll_free(int *epoll_fd)
|
||||
{
|
||||
if (*epoll_fd >= 0)
|
||||
close(*epoll_fd);
|
||||
|
||||
*epoll_fd = -1;
|
||||
}
|
||||
|
||||
bool epoll_add(int *epoll_fd, int fd, void *device)
|
||||
{
|
||||
struct epoll_event event;
|
||||
|
||||
event.events = EPOLLIN;
|
||||
event.data.ptr = device;
|
||||
|
||||
/* Shouldn't happen, but just check it. */
|
||||
if (epoll_ctl(*epoll_fd, EPOLL_CTL_ADD, fd, &event) < 0)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
/* RetroArch - A frontend for libretro.
|
||||
* Copyright (C) 2011-2017 - Daniel De Matteis
|
||||
*
|
||||
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Found-
|
||||
* ation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with RetroArch.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _EPOLL_COMMON_H
|
||||
#define _EPOLL_COMMON_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <boolean.h>
|
||||
|
||||
bool epoll_new(int *epoll_fd);
|
||||
|
||||
void epoll_free(int *epoll_fd);
|
||||
|
||||
bool epoll_add(int *epoll_fd, int fd, void *device);
|
||||
|
||||
#endif
|
@ -43,7 +43,6 @@
|
||||
|
||||
#include "../../gfx/video_driver.h"
|
||||
#include "../common/linux_common.h"
|
||||
#include "../common/epoll_common.h"
|
||||
|
||||
#include "../../gfx/common/wayland_common.h"
|
||||
|
||||
|
@ -33,7 +33,6 @@
|
||||
#include "../input_config.h"
|
||||
#include "../input_driver.h"
|
||||
|
||||
#include "../common/epoll_common.h"
|
||||
#include "../../verbosity.h"
|
||||
#include "../../tasks/tasks_internal.h"
|
||||
|
||||
@ -97,6 +96,8 @@ static bool linuxraw_joypad_init_pad(const char *path,
|
||||
|
||||
if (pad->fd >= 0)
|
||||
{
|
||||
struct epoll_event event;
|
||||
|
||||
if (ioctl(pad->fd,
|
||||
JSIOCGNAME(sizeof(input_device_names[0])), pad->ident) >= 0)
|
||||
{
|
||||
@ -105,13 +106,16 @@ static bool linuxraw_joypad_init_pad(const char *path,
|
||||
else
|
||||
RARCH_ERR("[Device]: Didn't find ident of %s.\n", path);
|
||||
|
||||
if (epoll_add(&linuxraw_epoll, pad->fd, pad))
|
||||
return true;
|
||||
else
|
||||
event.events = EPOLLIN;
|
||||
event.data.ptr = pad;
|
||||
|
||||
if (epoll_ctl(linuxraw_epoll, EPOLL_CTL_ADD, pad->fd, &event) < 0)
|
||||
{
|
||||
RARCH_ERR("Failed to add FD (%d) to epoll list (%s).\n",
|
||||
pad->fd, strerror(errno));
|
||||
}
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
RARCH_ERR("[Device]: Failed to open pad %s (error: %s).\n",
|
||||
@ -232,10 +236,13 @@ retry:
|
||||
static bool linuxraw_joypad_init(void *data)
|
||||
{
|
||||
unsigned i;
|
||||
int fd = epoll_create(32);
|
||||
|
||||
if (!epoll_new(&linuxraw_epoll))
|
||||
if (fd < 0)
|
||||
return false;
|
||||
|
||||
linuxraw_epoll = fd;
|
||||
|
||||
for (i = 0; i < MAX_USERS; i++)
|
||||
{
|
||||
char path[PATH_MAX_LENGTH];
|
||||
@ -265,9 +272,16 @@ static bool linuxraw_joypad_init(void *data)
|
||||
|
||||
if (linuxraw_inotify >= 0)
|
||||
{
|
||||
struct epoll_event event;
|
||||
|
||||
fcntl(linuxraw_inotify, F_SETFL, fcntl(linuxraw_inotify, F_GETFL) | O_NONBLOCK);
|
||||
inotify_add_watch(linuxraw_inotify, "/dev/input", IN_DELETE | IN_CREATE | IN_ATTRIB);
|
||||
if (!epoll_add(&linuxraw_epoll, linuxraw_inotify, NULL))
|
||||
|
||||
event.events = EPOLLIN;
|
||||
event.data.ptr = NULL;
|
||||
|
||||
/* Shouldn't happen, but just check it. */
|
||||
if (epoll_ctl(linuxraw_epoll, EPOLL_CTL_ADD, linuxraw_inotify, &event) < 0)
|
||||
{
|
||||
RARCH_ERR("Failed to add FD (%d) to epoll list (%s).\n",
|
||||
linuxraw_inotify, strerror(errno));
|
||||
@ -298,7 +312,9 @@ static void linuxraw_joypad_destroy(void)
|
||||
close(linuxraw_inotify);
|
||||
linuxraw_inotify = -1;
|
||||
|
||||
epoll_free(&linuxraw_epoll);
|
||||
if (linuxraw_epoll >= 0)
|
||||
close(linuxraw_epoll);
|
||||
linuxraw_epoll = -1;
|
||||
|
||||
linuxraw_hotplug = false;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user