Make g_epoll static

This commit is contained in:
twinaphex 2015-11-30 18:14:07 +01:00
parent 54655c37cd
commit 7cb78cca58
4 changed files with 32 additions and 23 deletions

View File

@ -1,9 +1,13 @@
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include "epoll_common.h"
int g_epoll;
#include "../../verbosity.h"
static int g_epoll;
static bool epoll_inited;
static bool epoll_first_inited_is_joypad;
@ -39,3 +43,21 @@ int epoll_waiting(struct epoll_event *events, int maxevents, int timeout)
{
return epoll_wait(g_epoll, events, maxevents, timeout);
}
bool epoll_add(int fd, void *device)
{
struct epoll_event event = {0};
event.events = EPOLLIN;
event.data.ptr = device;
/* Shouldn't happen, but just check it. */
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));
return false;
}
return true;
}

View File

@ -23,12 +23,12 @@
#include <boolean.h>
extern int g_epoll;
bool epoll_new(bool is_joypad);
void epoll_free(bool is_joypad);
int epoll_waiting(struct epoll_event *events, int maxevents, int timeout);
bool epoll_add(int fd, void *device);
#endif

View File

@ -224,7 +224,6 @@ static bool add_device(udev_input_t *udev,
udev_input_device_t **tmp;
udev_input_device_t *device = NULL;
struct stat st = {0};
struct epoll_event event = {0};
if (stat(devnode, &st) < 0)
return false;
@ -258,13 +257,7 @@ static bool add_device(udev_input_t *udev,
tmp[udev->num_devices++] = device;
udev->devices = tmp;
event.events = EPOLLIN;
event.data.ptr = device;
/* Shouldn't happen, but just check it. */
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));
epoll_add(fd, device);
return true;

View File

@ -89,8 +89,6 @@ static bool linuxraw_joypad_init_pad(const char *path, struct linuxraw_joypad *p
*pad->ident = '\0';
if (pad->fd >= 0)
{
struct epoll_event event;
if (ioctl(pad->fd, JSIOCGNAME(sizeof(settings->input.device_names[0])), pad->ident) >= 0)
{
RARCH_LOG("[Device]: Found pad: %s on %s.\n", pad->ident, path);
@ -103,16 +101,16 @@ static bool linuxraw_joypad_init_pad(const char *path, struct linuxraw_joypad *p
rarch_main_msg_queue_push(msg, 0, 60, false);
}
}
else
RARCH_ERR("[Device]: Didn't find ident of %s.\n", path);
event.events = EPOLLIN;
event.data.ptr = pad;
epoll_ctl(g_epoll, EPOLL_CTL_ADD, pad->fd, &event);
if (!epoll_add(pad->fd, pad))
goto error;
return true;
}
error:
RARCH_ERR("[Device]: Failed to open pad %s (error: %s).\n", path, strerror(errno));
return false;
}
@ -253,15 +251,11 @@ static bool linuxraw_joypad_init(void *data)
}
g_notify = inotify_init();
if (g_notify >= 0)
{
struct epoll_event event;
linuxraw_joypad_setup_notify();
event.events = EPOLLIN;
event.data.ptr = NULL;
epoll_ctl(g_epoll, EPOLL_CTL_ADD, g_notify, &event);
epoll_add(g_notify, NULL);
}
g_hotplug = true;