(linuxraw_joypad.c) Cleanups

This commit is contained in:
twinaphex 2016-12-01 16:42:21 +01:00
parent d7f7d5f99a
commit b63b675274
3 changed files with 6 additions and 21 deletions

View File

@ -26,36 +26,21 @@
#include "../../verbosity.h" #include "../../verbosity.h"
static bool epoll_inited; bool epoll_new(int *epoll_fd)
static bool epoll_first_inited_is_joypad;
bool epoll_new(int *epoll_fd, bool is_joypad)
{ {
if (epoll_inited)
return true;
*epoll_fd = epoll_create(32); *epoll_fd = epoll_create(32);
if (*epoll_fd < 0) if (*epoll_fd < 0)
return false; return false;
epoll_first_inited_is_joypad = is_joypad;
epoll_inited = true;
return true; return true;
} }
void epoll_free(int *epoll_fd, bool is_joypad) void epoll_free(int *epoll_fd)
{ {
if (!epoll_inited || (is_joypad && !epoll_first_inited_is_joypad))
return;
if (*epoll_fd >= 0) if (*epoll_fd >= 0)
close(*epoll_fd); close(*epoll_fd);
*epoll_fd = -1; *epoll_fd = -1;
epoll_inited = false;
epoll_first_inited_is_joypad = false;
} }
int epoll_waiting(int *epoll_fd, void *events, int maxevents, int timeout) int epoll_waiting(int *epoll_fd, void *events, int maxevents, int timeout)

View File

@ -20,9 +20,9 @@
#include <boolean.h> #include <boolean.h>
bool epoll_new(int *epoll_fd, bool is_joypad); bool epoll_new(int *epoll_fd);
void epoll_free(int *epoll_fd, bool is_joypad); void epoll_free(int *epoll_fd);
int epoll_waiting(int *epoll_fd, void *events, int maxevents, int timeout); int epoll_waiting(int *epoll_fd, void *events, int maxevents, int timeout);

View File

@ -228,7 +228,7 @@ static bool linuxraw_joypad_init(void *data)
{ {
unsigned i; unsigned i;
if (!epoll_new(&linuxraw_epoll, true)) if (!epoll_new(&linuxraw_epoll))
return false; return false;
for (i = 0; i < MAX_USERS; i++) for (i = 0; i < MAX_USERS; i++)
@ -292,7 +292,7 @@ static void linuxraw_joypad_destroy(void)
close(linuxraw_inotify); close(linuxraw_inotify);
linuxraw_inotify = -1; linuxraw_inotify = -1;
epoll_free(&linuxraw_epoll, true); epoll_free(&linuxraw_epoll);
linuxraw_hotplug = false; linuxraw_hotplug = false;
} }