(tasks) Cleanups

This commit is contained in:
twinaphex 2019-05-23 13:05:15 +02:00
parent 2db271d954
commit 9bc0478e9d
2 changed files with 48 additions and 50 deletions

View File

@ -154,7 +154,6 @@ void input_autoconfigure_joypad_reindex_devices(void)
{
/*Mark the first device of the set*/
input_device_name_index[i] = 1;
/*count this additional device, from two up*/
input_device_name_index[j] = k++;
}
@ -324,7 +323,6 @@ static bool input_autoconfigure_joypad_from_conf_dir(
int ret = 0;
int index = -1;
int current_best = 0;
config_file_t *conf = NULL;
struct string_list *list = NULL;
path[0] = '\0';
@ -356,7 +354,7 @@ static bool input_autoconfigure_joypad_from_conf_dir(
for (i = 0; i < list->size; i++)
{
conf = config_file_new(list->elems[i].data);
config_file_t *conf = config_file_new(list->elems[i].data);
if (conf)
ret = input_autoconfigure_joypad_try_from_conf(conf, params);
@ -371,7 +369,7 @@ static bool input_autoconfigure_joypad_from_conf_dir(
if (index >= 0 && current_best > 0)
{
conf = config_file_new(list->elems[index].data);
config_file_t *conf = config_file_new(list->elems[index].data);
if (conf)
{
@ -824,12 +822,9 @@ static void input_autoconfigure_override_handler(autoconfig_params_t *params)
blissbox_pads[index] = pad;
}
/* use NULL entry to mark as an unconnected port */
else
{
int count = sizeof(blissbox_pad_types) / sizeof(blissbox_pad_types[0]);
/* use NULL entry to mark as an unconnected port */
blissbox_pads[index] = &blissbox_pad_types[count - 1];
}
blissbox_pads[index] = &blissbox_pad_types[ARRAY_SIZE(blissbox_pad_types) - 1];
}
}
}

View File

@ -220,19 +220,26 @@ static autosave_t *autosave_new(const char *path,
const void *data, size_t size,
unsigned interval)
{
void *buf = NULL;
autosave_t *handle = (autosave_t*)malloc(sizeof(*handle));
if (!handle)
goto error;
return NULL;
handle->quit = false;
handle->bufsize = size;
handle->interval = interval;
handle->buffer = malloc(size);
handle->retro_buffer = data;
handle->path = path;
if (!handle->buffer)
goto error;
buf = malloc(size);
if (!buf)
{
free(handle);
return false;
}
handle->buffer = buf;
memcpy(handle->buffer, handle->retro_buffer, handle->bufsize);
@ -242,11 +249,6 @@ static autosave_t *autosave_new(const char *path,
handle->thread = sthread_create(autosave_thread, handle);
return handle;
error:
if (handle)
free(handle);
return NULL;
}
/**
@ -624,11 +626,11 @@ static void task_save_handler(retro_task_t *task)
remaining = MIN(state->size - state->written, SAVE_STATE_CHUNK);
if ( state->data )
written = (int)intfstream_write(state->file,
if (state->data)
written = (int)intfstream_write(state->file,
(uint8_t*)state->data + state->written, remaining);
else
written = 0;
written = 0;
state->written += written;
@ -1167,23 +1169,36 @@ static void content_load_and_save_state_cb(retro_task_t *task,
static void task_push_load_and_save_state(const char *path, void *data,
size_t size, bool load_to_backup_buffer, bool autosave)
{
retro_task_t *task = task_init();
save_task_state_t *state = (save_task_state_t*)calloc(1, sizeof(*state));
settings_t *settings = config_get_ptr();
retro_task_t *task = NULL;
settings_t *settings = NULL;
save_task_state_t *state = (save_task_state_t*)
calloc(1, sizeof(*state));
if (!task || !state)
goto error;
if (!state)
return;
task = task_init();
if (!task)
{
free(state);
return;
}
settings = config_get_ptr();
strlcpy(state->path, path, sizeof(state->path));
state->load_to_backup_buffer = load_to_backup_buffer;
state->undo_size = size;
state->undo_data = data;
state->autosave = autosave;
state->mute = autosave; /* don't show OSD messages if we are auto-saving */
if(load_to_backup_buffer)
state->mute = true;
state->state_slot = settings->ints.state_slot;
state->has_valid_framebuffer = video_driver_cached_frame_has_valid_framebuffer();
state->mute = autosave; /* don't show OSD messages if we
are auto-saving */
if (load_to_backup_buffer)
state->mute = true;
state->state_slot = settings->ints.state_slot;
state->has_valid_framebuffer =
video_driver_cached_frame_has_valid_framebuffer();
task->state = state;
task->type = TASK_TYPE_BLOCKING;
@ -1202,16 +1217,6 @@ static void task_push_load_and_save_state(const char *path, void *data,
free(task);
free(state);
}
return;
error:
if (data)
free(data);
if (state)
free(state);
if (task)
free(task);
}
/**
@ -1331,7 +1336,8 @@ bool content_load_state(const char *path,
state->load_to_backup_buffer = load_to_backup_buffer;
state->autoload = autoload;
state->state_slot = settings->ints.state_slot;
state->has_valid_framebuffer = video_driver_cached_frame_has_valid_framebuffer();
state->has_valid_framebuffer =
video_driver_cached_frame_has_valid_framebuffer();
task->type = TASK_TYPE_BLOCKING;
task->state = state;
@ -1369,8 +1375,8 @@ bool content_rename_state(const char *origin, const char *dest)
/*
*
* TODO/FIXME: Figure out when and where this should be called.
* As it is, when e.g. closing Gambatte, we get the same printf message 4 times.
*
* As it is, when e.g. closing Gambatte, we get the
* same printf message 4 times.
*/
bool content_reset_savestate_backups(void)
{
@ -1499,12 +1505,9 @@ static bool dump_to_file_desperate(const void *data,
path[0] = '\0';
snprintf(path,
PATH_MAX_LENGTH * sizeof(char),
"%s/RetroArch-recovery-%u",
application_data, type);
strlcat(path, timebuf,
PATH_MAX_LENGTH * sizeof(char)
);
"%s/RetroArch-recovery-%u%s",
application_data, type,
timebuf);
free(application_data);
free(timebuf);