1
0
mirror of https://github.com/libretro/RetroArch synced 2025-02-15 18:39:55 +00:00

Create epoll_common

This commit is contained in:
twinaphex 2015-11-30 18:05:10 +01:00
parent 0637671725
commit ecbfc72e9b
6 changed files with 77 additions and 17 deletions

@ -78,6 +78,7 @@ 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

@ -375,6 +375,7 @@ 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

@ -0,0 +1,35 @@
#include <stdio.h>
#include "epoll_common.h"
int g_epoll;
static bool epoll_inited;
static bool epoll_first_inited_is_joypad;
bool epoll_new(bool is_joypad)
{
if (epoll_inited)
return true;
g_epoll = epoll_create(32);
if (g_epoll < 0)
return false;
epoll_first_inited_is_joypad = is_joypad;
epoll_inited = true;
return true;
}
void epoll_free(bool is_joypad)
{
if (!epoll_inited || (is_joypad && !epoll_first_inited_is_joypad))
return;
if (g_epoll >= 0)
close(g_epoll);
g_epoll = -1;
epoll_inited = false;
epoll_first_inited_is_joypad = false;
}

@ -0,0 +1,32 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2011-2015 - 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 <fcntl.h>
#include <sys/epoll.h>
#include <boolean.h>
extern int g_epoll;
bool epoll_new(bool is_joypad);
void epoll_free(bool is_joypad);
#endif

@ -24,8 +24,6 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/epoll.h>
#include <libudev.h>
#include <linux/types.h>
#include <linux/input.h>
@ -35,6 +33,7 @@
#include "../drivers_keyboard/keyboard_event_udev.h"
#include "../common/linux_common.h"
#include "../common/epoll_common.h"
#include "../common/udev_common.h"
#include "../input_config.h"
@ -81,7 +80,6 @@ struct udev_input
bool blocked;
const input_device_driver_t *joypad;
int epfd;
udev_input_device_t **devices;
unsigned num_devices;
@ -264,7 +262,7 @@ static bool add_device(udev_input_t *udev,
event.data.ptr = device;
/* Shouldn't happen, but just check it. */
if (epoll_ctl(udev->epfd, EPOLL_CTL_ADD, fd, &event) < 0)
if (epoll_ctl(g_epoll, EPOLL_CTL_ADD, fd, &event) < 0)
RARCH_ERR("Failed to add FD (%d) to epoll list (%s).\n",
fd, strerror(errno));
@ -367,7 +365,7 @@ static void udev_input_poll(void *data)
while (udev_mon_hotplug_available())
udev_input_handle_hotplug(udev);
ret = epoll_wait(udev->epfd, events, ARRAY_SIZE(events), 0);
ret = epoll_wait(g_epoll, events, ARRAY_SIZE(events), 0);
for (i = 0; i < ret; i++)
{
@ -559,8 +557,7 @@ static void udev_input_free(void *data)
if (udev->joypad)
udev->joypad->destroy();
if (udev->epfd >= 0)
close(udev->epfd);
epoll_free(false);
for (i = 0; i < udev->num_devices; i++)
{
@ -629,8 +626,7 @@ static void *udev_input_init(void)
goto error;
#endif
udev->epfd = epoll_create(32);
if (udev->epfd < 0)
if (!epoll_new(false))
{
RARCH_ERR("Failed to create epoll FD.\n");
goto error;

@ -21,10 +21,9 @@
#include <sys/types.h>
#include <sys/inotify.h>
#include <sys/epoll.h>
#include <fcntl.h>
#include <linux/joystick.h>
#include "../common/epoll_common.h"
#include "../input_autodetect.h"
#include "../../general.h"
#include "../../verbosity.h"
@ -43,7 +42,6 @@ struct linuxraw_joypad
static struct linuxraw_joypad linuxraw_pads[MAX_USERS];
static int g_notify;
static int g_epoll;
static bool g_hotplug;
static void linuxraw_poll_pad(struct linuxraw_joypad *pad)
@ -220,8 +218,7 @@ static bool linuxraw_joypad_init(void *data)
unsigned i;
settings_t *settings = config_get_ptr();
g_epoll = epoll_create(MAX_USERS + 1);
if (g_epoll < 0)
if (!epoll_new(true))
return false;
(void)data;
@ -291,9 +288,7 @@ static void linuxraw_joypad_destroy(void)
close(g_notify);
g_notify = -1;
if (g_epoll >= 0)
close(g_epoll);
g_epoll = -1;
epoll_free(true);
g_hotplug = false;
}