(task_autodetect.c) Solve some threading errors

This commit is contained in:
twinaphex 2016-12-29 05:49:24 +01:00
parent 31aa1d6d19
commit 3a581ba8b0

View File

@ -289,31 +289,11 @@ static bool input_autoconfigure_joypad_from_conf_internal(
return false;
}
static bool input_autoconfigure_joypad_init(autoconfig_params_t *params)
{
size_t i;
settings_t *settings = config_get_ptr();
if (!settings || !settings->input.autodetect_enable)
return false;
for (i = 0; i < RARCH_BIND_LIST_END; i++)
{
settings->input.autoconf_binds[params->idx][i].joykey = NO_BTN;
settings->input.autoconf_binds[params->idx][i].joyaxis = AXIS_NONE;
settings->input.autoconf_binds[params->idx][i].joykey_label[0] = '\0';
settings->input.autoconf_binds[params->idx][i].joyaxis_label[0] = '\0';
}
settings->input.autoconfigured[params->idx] = false;
return true;
}
static void input_autoconfigure_connect_handler(retro_task_t *task)
{
autoconfig_params_t *params = (autoconfig_params_t*)task->state;
if (!params || !input_autoconfigure_joypad_init(params) || string_is_empty(params->name))
if (!params || string_is_empty(params->name))
{
free(params);
task->finished = true;
@ -343,13 +323,10 @@ static void input_autoconfigure_connect_handler(retro_task_t *task)
static void input_autoconfigure_disconnect_handler(retro_task_t *task)
{
autoconfig_disconnect_t *params = (autoconfig_disconnect_t*)task->state;
settings_t *settings = config_get_ptr();
task->title = strdup(params->msg);
task->finished = true;
settings->input.device_names[params->idx][0] = '\0';
RARCH_LOG("%s: %s\n", msg_hash_to_str(MSG_AUTODETECT), params->msg);
free(params);
@ -360,6 +337,7 @@ bool input_autoconfigure_disconnect(unsigned i, const char *ident)
char msg[255];
retro_task_t *task = (retro_task_t*)calloc(1, sizeof(*task));
autoconfig_disconnect_t *state = (autoconfig_disconnect_t*)calloc(1, sizeof(*state));
settings_t *settings = config_get_ptr();
if (!state || !task)
goto error;
@ -374,6 +352,8 @@ bool input_autoconfigure_disconnect(unsigned i, const char *ident)
strlcpy(state->msg, msg, sizeof(state->msg));
settings->input.device_names[state->idx][0] = '\0';
task->state = state;
task->handler = input_autoconfigure_disconnect_handler;
@ -392,6 +372,7 @@ error:
bool input_autoconfigure_connect(autoconfig_params_t *params)
{
unsigned i;
retro_task_t *task = (retro_task_t*)calloc(1, sizeof(*task));
autoconfig_params_t *state = (autoconfig_params_t*)calloc(1, sizeof(*state));
settings_t *settings = config_get_ptr();
@ -401,6 +382,15 @@ bool input_autoconfigure_connect(autoconfig_params_t *params)
strlcpy(state->name, params->name, sizeof(state->name));
for (i = 0; i < RARCH_BIND_LIST_END; i++)
{
settings->input.autoconf_binds[params->idx][i].joykey = NO_BTN;
settings->input.autoconf_binds[params->idx][i].joyaxis = AXIS_NONE;
settings->input.autoconf_binds[params->idx][i].joykey_label[0] = '\0';
settings->input.autoconf_binds[params->idx][i].joyaxis_label[0] = '\0';
}
settings->input.autoconfigured[params->idx] = false;
state->idx = params->idx;
state->vid = params->vid;
state->pid = params->pid;