mirror of
https://github.com/libretro/RetroArch
synced 2025-04-03 10:21:31 +00:00
(task_save.c) Cleanups
This commit is contained in:
parent
43459e2269
commit
d6aae88737
@ -90,13 +90,11 @@ struct string_list *string_list_new(void)
|
|||||||
if (!list)
|
if (!list)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (!string_list_capacity(list, 32))
|
if (string_list_capacity(list, 32))
|
||||||
{
|
return list;
|
||||||
string_list_free(list);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return list;
|
string_list_free(list);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -301,8 +299,9 @@ bool string_list_find_elem_prefix(const struct string_list *list,
|
|||||||
|
|
||||||
for (i = 0; i < list->size; i++)
|
for (i = 0; i < list->size; i++)
|
||||||
{
|
{
|
||||||
if (strcasecmp(list->elems[i].data, elem) == 0 ||
|
const char *data = list->elems[i].data;
|
||||||
strcasecmp(list->elems[i].data, prefixed) == 0)
|
if ( (strcasecmp(data, elem) == 0)
|
||||||
|
|| (strcasecmp(data, prefixed) == 0))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,7 +142,7 @@ static void autosave_thread(void *data)
|
|||||||
bool first_log = true;
|
bool first_log = true;
|
||||||
autosave_t *save = (autosave_t*)data;
|
autosave_t *save = (autosave_t*)data;
|
||||||
|
|
||||||
while (!save->quit)
|
while (save && !save->quit)
|
||||||
{
|
{
|
||||||
bool differ;
|
bool differ;
|
||||||
|
|
||||||
@ -207,6 +207,7 @@ static autosave_t *autosave_new(const char *path,
|
|||||||
const void *data, size_t size,
|
const void *data, size_t size,
|
||||||
unsigned interval)
|
unsigned interval)
|
||||||
{
|
{
|
||||||
|
void *buffer = NULL;
|
||||||
autosave_t *handle = (autosave_t*)calloc(1, sizeof(*handle));
|
autosave_t *handle = (autosave_t*)calloc(1, sizeof(*handle));
|
||||||
if (!handle)
|
if (!handle)
|
||||||
goto error;
|
goto error;
|
||||||
@ -214,18 +215,19 @@ static autosave_t *autosave_new(const char *path,
|
|||||||
handle->bufsize = size;
|
handle->bufsize = size;
|
||||||
handle->interval = interval;
|
handle->interval = interval;
|
||||||
handle->path = path;
|
handle->path = path;
|
||||||
handle->buffer = malloc(size);
|
|
||||||
handle->retro_buffer = data;
|
handle->retro_buffer = data;
|
||||||
|
|
||||||
if (!handle->buffer)
|
buffer = malloc(size);
|
||||||
|
|
||||||
|
if (!buffer)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
memcpy(handle->buffer, handle->retro_buffer, handle->bufsize);
|
memcpy(buffer, handle->retro_buffer, handle->bufsize);
|
||||||
|
|
||||||
|
handle->buffer = buffer;
|
||||||
handle->lock = slock_new();
|
handle->lock = slock_new();
|
||||||
handle->cond_lock = slock_new();
|
handle->cond_lock = slock_new();
|
||||||
handle->cond = scond_new();
|
handle->cond = scond_new();
|
||||||
|
|
||||||
handle->thread = sthread_create(autosave_thread, handle);
|
handle->thread = sthread_create(autosave_thread, handle);
|
||||||
|
|
||||||
return handle;
|
return handle;
|
||||||
@ -279,26 +281,35 @@ void autosave_init(void)
|
|||||||
autosave_state.list = list;
|
autosave_state.list = list;
|
||||||
autosave_state.num = task_save_files->size;
|
autosave_state.num = task_save_files->size;
|
||||||
|
|
||||||
|
if (!task_save_files)
|
||||||
|
return;
|
||||||
|
|
||||||
for (i = 0; i < task_save_files->size; i++)
|
for (i = 0; i < task_save_files->size; i++)
|
||||||
{
|
{
|
||||||
retro_ctx_memory_info_t mem_info;
|
retro_ctx_memory_info_t mem_info;
|
||||||
const char *path = task_save_files->elems[i].data;
|
autosave_t *autosave = NULL;
|
||||||
unsigned type = task_save_files->elems[i].attr.i;
|
const char *path = task_save_files->elems[i].data;
|
||||||
|
unsigned type = task_save_files->elems[i].attr.i;
|
||||||
|
|
||||||
mem_info.id = type;
|
mem_info.id = type;
|
||||||
|
|
||||||
core_get_memory(&mem_info);
|
core_get_memory(&mem_info);
|
||||||
|
|
||||||
if (mem_info.size <= 0)
|
if (mem_info.size <= 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
autosave_state.list[i] = autosave_new(path,
|
autosave = autosave_new(path,
|
||||||
mem_info.data,
|
mem_info.data,
|
||||||
mem_info.size,
|
mem_info.size,
|
||||||
settings->autosave_interval);
|
settings->autosave_interval);
|
||||||
|
|
||||||
if (!autosave_state.list[i])
|
if (!autosave)
|
||||||
|
{
|
||||||
RARCH_WARN("%s\n", msg_hash_to_str(MSG_AUTOSAVE_FAILED));
|
RARCH_WARN("%s\n", msg_hash_to_str(MSG_AUTOSAVE_FAILED));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
autosave_state.list[i] = autosave;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -611,8 +622,6 @@ static void task_save_handler(retro_task_t *task)
|
|||||||
task->title = strdup(msg);
|
task->title = strdup(msg);
|
||||||
|
|
||||||
task_save_handler_finished(task, state);
|
task_save_handler_finished(task, state);
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -633,15 +642,15 @@ static bool task_push_undo_save_state(const char *path, void *data, size_t size)
|
|||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
strlcpy(state->path, path, sizeof(state->path));
|
strlcpy(state->path, path, sizeof(state->path));
|
||||||
state->data = data;
|
state->data = data;
|
||||||
state->size = size;
|
state->size = size;
|
||||||
state->undo_save = true;
|
state->undo_save = true;
|
||||||
|
|
||||||
task->type = TASK_TYPE_BLOCKING;
|
task->type = TASK_TYPE_BLOCKING;
|
||||||
task->state = state;
|
task->state = state;
|
||||||
task->handler = task_save_handler;
|
task->handler = task_save_handler;
|
||||||
task->callback = undo_save_state_cb;
|
task->callback = undo_save_state_cb;
|
||||||
task->title = strdup(msg_hash_to_str(MSG_UNDOING_SAVE_STATE));
|
task->title = strdup(msg_hash_to_str(MSG_UNDOING_SAVE_STATE));
|
||||||
|
|
||||||
task_queue_ctl(TASK_QUEUE_CTL_PUSH, task);
|
task_queue_ctl(TASK_QUEUE_CTL_PUSH, task);
|
||||||
|
|
||||||
@ -667,8 +676,7 @@ error:
|
|||||||
bool content_undo_save_state(void)
|
bool content_undo_save_state(void)
|
||||||
{
|
{
|
||||||
return task_push_undo_save_state(undo_save_buf.path,
|
return task_push_undo_save_state(undo_save_buf.path,
|
||||||
undo_save_buf.data,
|
undo_save_buf.data, undo_save_buf.size);
|
||||||
undo_save_buf.size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -800,8 +808,6 @@ static void task_load_handler(retro_task_t *task)
|
|||||||
}
|
}
|
||||||
|
|
||||||
task_load_handler_finished(task, state);
|
task_load_handler_finished(task, state);
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -823,11 +829,11 @@ static void content_load_state_cb(void *task_data,
|
|||||||
unsigned i;
|
unsigned i;
|
||||||
bool ret;
|
bool ret;
|
||||||
char err_buf[1024];
|
char err_buf[1024];
|
||||||
|
unsigned num_blocks = 0;
|
||||||
|
struct sram_block *blocks = NULL;
|
||||||
load_task_data_t *load_data = (load_task_data_t*)task_data;
|
load_task_data_t *load_data = (load_task_data_t*)task_data;
|
||||||
ssize_t size = load_data->size;
|
ssize_t size = load_data->size;
|
||||||
unsigned num_blocks = 0;
|
|
||||||
void *buf = load_data->data;
|
void *buf = load_data->data;
|
||||||
struct sram_block *blocks = NULL;
|
|
||||||
settings_t *settings = config_get_ptr();
|
settings_t *settings = config_get_ptr();
|
||||||
|
|
||||||
err_buf[0] = '\0';
|
err_buf[0] = '\0';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user