Add grab_stdin function pointer to input driver - avoids threading

segfault at exit with linuxraw input driver to do with driver->stdin_claimed
This commit is contained in:
twinaphex 2015-05-19 19:33:58 +02:00
parent d662ac187d
commit 3a7263020a
20 changed files with 40 additions and 7 deletions

View File

@ -52,14 +52,14 @@ static void event_init_command(void)
if (!settings->stdin_cmd_enable && !settings->network_cmd_enable) if (!settings->stdin_cmd_enable && !settings->network_cmd_enable)
return; return;
if (settings->stdin_cmd_enable && driver->stdin_claimed) if (settings->stdin_cmd_enable && input_driver_grab_stdin())
{ {
RARCH_WARN("stdin command interface is desired, but input driver has already claimed stdin.\n" RARCH_WARN("stdin command interface is desired, but input driver has already claimed stdin.\n"
"Cannot use this command interface.\n"); "Cannot use this command interface.\n");
} }
if (!(driver->command = rarch_cmd_new(settings->stdin_cmd_enable if (!(driver->command = rarch_cmd_new(settings->stdin_cmd_enable
&& !driver->stdin_claimed, && !input_driver_grab_stdin(),
settings->network_cmd_enable, settings->network_cmd_port))) settings->network_cmd_enable, settings->network_cmd_port)))
RARCH_ERR("Failed to initialize command interface.\n"); RARCH_ERR("Failed to initialize command interface.\n");
} }

View File

@ -263,7 +263,6 @@ typedef struct driver
#ifdef HAVE_COMMAND #ifdef HAVE_COMMAND
rarch_cmd_t *command; rarch_cmd_t *command;
#endif #endif
bool stdin_claimed;
bool block_hotkey; bool block_hotkey;
bool block_input; bool block_input;
bool block_libretro_input; bool block_libretro_input;

View File

@ -1062,6 +1062,7 @@ input_driver_t input_android = {
"android", "android",
android_input_grab_mouse, android_input_grab_mouse,
NULL,
android_input_set_rumble, android_input_set_rumble,
android_input_get_joypad_driver, android_input_get_joypad_driver,
}; };

View File

@ -434,6 +434,7 @@ input_driver_t input_cocoa = {
cocoa_input_get_capabilities, cocoa_input_get_capabilities,
"cocoa", "cocoa",
cocoa_input_grab_mouse, cocoa_input_grab_mouse,
NULL,
cocoa_input_set_rumble, cocoa_input_set_rumble,
cocoa_input_get_joypad_driver cocoa_input_get_joypad_driver
}; };

View File

@ -132,6 +132,7 @@ input_driver_t input_ctr = {
ctr_input_get_capabilities, ctr_input_get_capabilities,
"ctr", "ctr",
ctr_input_grab_mouse, ctr_input_grab_mouse,
NULL,
ctr_input_set_rumble, ctr_input_set_rumble,
ctr_input_get_joypad_driver, ctr_input_get_joypad_driver,
}; };

View File

@ -685,6 +685,7 @@ input_driver_t input_dinput = {
"dinput", "dinput",
dinput_grab_mouse, dinput_grab_mouse,
NULL,
dinput_set_rumble, dinput_set_rumble,
dinput_get_joypad_driver, dinput_get_joypad_driver,
}; };

View File

@ -141,6 +141,7 @@ input_driver_t input_gx = {
"gx", "gx",
gx_input_grab_mouse, gx_input_grab_mouse,
NULL,
gx_input_set_rumble, gx_input_set_rumble,
gx_input_get_joypad_driver, gx_input_get_joypad_driver,
}; };

View File

@ -28,6 +28,7 @@
#include "../input_joypad.h" #include "../input_joypad.h"
static long oldKbmd = 0xffff; static long oldKbmd = 0xffff;
static bool linuxraw_stdin_claimed = false;
static struct termios oldTerm, newTerm; static struct termios oldTerm, newTerm;
typedef struct linuxraw_input typedef struct linuxraw_input
@ -39,7 +40,6 @@ typedef struct linuxraw_input
static void linuxraw_reset_kbmd(void) static void linuxraw_reset_kbmd(void)
{ {
driver_t *driver = driver_get_ptr();
if (oldKbmd != 0xffff) if (oldKbmd != 0xffff)
{ {
ioctl(0, KDSKBMODE, oldKbmd); ioctl(0, KDSKBMODE, oldKbmd);
@ -47,7 +47,7 @@ static void linuxraw_reset_kbmd(void)
oldKbmd = 0xffff; oldKbmd = 0xffff;
} }
driver->stdin_claimed = false; linuxraw_stdin_claimed = false;
} }
static void linuxraw_exit_gracefully(int sig) static void linuxraw_exit_gracefully(int sig)
@ -67,7 +67,7 @@ static void *linuxraw_input_init(void)
if (!isatty(0)) if (!isatty(0))
return NULL; return NULL;
if (driver->stdin_claimed) if (linuxraw_stdin_claimed)
{ {
RARCH_WARN("stdin is already used for content loading. Cannot use stdin for input.\n"); RARCH_WARN("stdin is already used for content loading. Cannot use stdin for input.\n");
return NULL; return NULL;
@ -122,11 +122,16 @@ static void *linuxraw_input_init(void)
/* We need to disable use of stdin command interface if /* We need to disable use of stdin command interface if
* stdin is supposed to be used for input. */ * stdin is supposed to be used for input. */
driver->stdin_claimed = true; linuxraw_stdin_claimed = true;
return linuxraw; return linuxraw;
} }
static bool linuxraw_grab_stdin(void *data)
{
return linuxraw_stdin_claimed;
}
static bool linuxraw_key_pressed(linuxraw_input_t *linuxraw, int key) static bool linuxraw_key_pressed(linuxraw_input_t *linuxraw, int key)
{ {
unsigned sym = input_keymaps_translate_rk_to_keysym((enum retro_key)key); unsigned sym = input_keymaps_translate_rk_to_keysym((enum retro_key)key);
@ -282,6 +287,7 @@ input_driver_t input_linuxraw = {
linuxraw_get_capabilities, linuxraw_get_capabilities,
"linuxraw", "linuxraw",
linuxraw_grab_mouse, linuxraw_grab_mouse,
linuxraw_grab_stdin,
linuxraw_set_rumble, linuxraw_set_rumble,
linuxraw_get_joypad_driver, linuxraw_get_joypad_driver,
}; };

View File

@ -97,5 +97,6 @@ input_driver_t input_null = {
nullinput_get_capabilities, nullinput_get_capabilities,
"null", "null",
nullinput_grab_mouse, nullinput_grab_mouse,
NULL,
nullinput_set_rumble, nullinput_set_rumble,
}; };

View File

@ -259,6 +259,7 @@ input_driver_t input_ps3 = {
"ps3", "ps3",
ps3_input_grab_mouse, ps3_input_grab_mouse,
NULL,
ps3_input_set_rumble, ps3_input_set_rumble,
ps3_input_get_joypad_driver, ps3_input_get_joypad_driver,
}; };

View File

@ -146,6 +146,7 @@ input_driver_t input_psp = {
"psp", "psp",
psp_input_grab_mouse, psp_input_grab_mouse,
NULL,
psp_input_set_rumble, psp_input_set_rumble,
psp_input_get_joypad_driver, psp_input_get_joypad_driver,
}; };

View File

@ -850,6 +850,7 @@ input_driver_t input_qnx = {
qnx_input_get_capabilities, qnx_input_get_capabilities,
"qnx_input", "qnx_input",
qnx_input_grab_mouse, qnx_input_grab_mouse,
NULL,
qnx_input_set_rumble, qnx_input_set_rumble,
qnx_input_get_joypad_driver, qnx_input_get_joypad_driver,
}; };

View File

@ -237,5 +237,6 @@ input_driver_t input_rwebinput = {
rwebinput_get_capabilities, rwebinput_get_capabilities,
"rwebinput", "rwebinput",
rwebinput_grab_mouse, rwebinput_grab_mouse,
NULL,
rwebinput_set_rumble, rwebinput_set_rumble,
}; };

View File

@ -395,6 +395,7 @@ input_driver_t input_sdl = {
"sdl", "sdl",
#endif #endif
sdl_grab_mouse, sdl_grab_mouse,
NULL,
sdl_set_rumble, sdl_set_rumble,
sdl_get_joypad_driver, sdl_get_joypad_driver,
}; };

View File

@ -874,6 +874,7 @@ input_driver_t input_udev = {
udev_input_get_capabilities, udev_input_get_capabilities,
"udev", "udev",
udev_input_grab_mouse, udev_input_grab_mouse,
NULL,
udev_input_set_rumble, udev_input_set_rumble,
udev_input_get_joypad_driver, udev_input_get_joypad_driver,
}; };

View File

@ -396,6 +396,7 @@ input_driver_t input_x = {
x_input_get_capabilities, x_input_get_capabilities,
"x", "x",
x_grab_mouse, x_grab_mouse,
NULL,
x_set_rumble, x_set_rumble,
x_get_joypad_driver, x_get_joypad_driver,
}; };

View File

@ -162,6 +162,7 @@ input_driver_t input_xinput = {
xdk_input_get_capabilities, xdk_input_get_capabilities,
"xinput", "xinput",
xdk_input_grab_mouse, xdk_input_grab_mouse,
NULL,
xdk_input_set_rumble, xdk_input_set_rumble,
xdk_input_get_joypad_driver, xdk_input_get_joypad_driver,
}; };

View File

@ -131,5 +131,6 @@ input_driver_t input_xenon360 = {
xenon360_input_get_capabilities, xenon360_input_get_capabilities,
"xenon360", "xenon360",
xenon360_input_grab_mouse, xenon360_input_grab_mouse,
NULL,
xenon360_input_set_rumble, xenon360_input_set_rumble,
}; };

View File

@ -290,6 +290,16 @@ bool input_driver_grab_mouse(bool state)
return false; return false;
} }
bool input_driver_grab_stdin(void)
{
driver_t *driver = driver_get_ptr();
const input_driver_t *input = input_get_ptr(driver);
if (input->grab_stdin)
return input->grab_stdin(driver->input_data);
return false;
}
void *input_driver_init(void) void *input_driver_init(void)
{ {
driver_t *driver = driver_get_ptr(); driver_t *driver = driver_get_ptr();

View File

@ -72,6 +72,7 @@ typedef struct input_driver
const char *ident; const char *ident;
void (*grab_mouse)(void *data, bool state); void (*grab_mouse)(void *data, bool state);
bool (*grab_stdin)(void *data);
bool (*set_rumble)(void *data, unsigned port, bool (*set_rumble)(void *data, unsigned port,
enum retro_rumble_effect effect, uint16_t state); enum retro_rumble_effect effect, uint16_t state);
const input_device_driver_t *(*get_joypad_driver)(void *data); const input_device_driver_t *(*get_joypad_driver)(void *data);
@ -151,6 +152,8 @@ const input_device_driver_t * input_driver_get_joypad_driver(void);
bool input_driver_grab_mouse(bool state); bool input_driver_grab_mouse(bool state);
bool input_driver_grab_stdin(void);
void *input_driver_init(void); void *input_driver_init(void);
void input_driver_free(void); void input_driver_free(void);