From 5d70131ce1bacb6a80ebc034bf1d92f1b2dd03f9 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Mon, 30 Nov 2015 19:23:13 +0100 Subject: [PATCH] Move global->autosave to autosave.c --- autosave.c | 73 +++++++++++++++++++++++++++++++++++++++++++------ autosave.h | 4 +++ command_event.c | 55 ++----------------------------------- runloop.c | 1 + runloop.h | 8 ------ 5 files changed, 72 insertions(+), 69 deletions(-) diff --git a/autosave.c b/autosave.c index edd6b9706a..44035b1bc9 100644 --- a/autosave.c +++ b/autosave.c @@ -22,9 +22,19 @@ #include -#include "general.h" +#include "autosave.h" +#include "configuration.h" +#include "msg_hash.h" +#include "runloop.h" #include "verbosity.h" +/* Autosave support. */ +struct autosave_st +{ + autosave_t **list; + unsigned num; +}; + struct autosave { volatile bool quit; @@ -41,6 +51,8 @@ struct autosave unsigned interval; }; +static struct autosave_st autosave_state; + /** * autosave_lock: * @handle : pointer to autosave object @@ -197,12 +209,11 @@ void autosave_free(autosave_t *handle) void lock_autosave(void) { unsigned i; - global_t *global = global_get_ptr(); - for (i = 0; i < global->autosave.num; i++) + for (i = 0; i < autosave_state.num; i++) { - if (global->autosave.list[i]) - autosave_lock(global->autosave.list[i]); + if (autosave_state.list[i]) + autosave_lock(autosave_state.list[i]); } } @@ -214,13 +225,57 @@ void lock_autosave(void) void unlock_autosave(void) { unsigned i; - global_t *global = global_get_ptr(); - for (i = 0; i < global->autosave.num; i++) + for (i = 0; i < autosave_state.num; i++) { - if (global->autosave.list[i]) - autosave_unlock(global->autosave.list[i]); + if (autosave_state.list[i]) + autosave_unlock(autosave_state.list[i]); } } +void autosave_event_init(void) +{ + unsigned i; + settings_t *settings = config_get_ptr(); + global_t *global = global_get_ptr(); + if (settings->autosave_interval < 1 || !global->savefiles) + return; + + if (!(autosave_state.list = (autosave_t**)calloc(global->savefiles->size, + sizeof(*autosave_state.list)))) + return; + + autosave_state.num = global->savefiles->size; + + for (i = 0; i < global->savefiles->size; i++) + { + const char *path = global->savefiles->elems[i].data; + unsigned type = global->savefiles->elems[i].attr.i; + + if (core.retro_get_memory_size(type) <= 0) + continue; + + autosave_state.list[i] = autosave_new(path, + core.retro_get_memory_data(type), + core.retro_get_memory_size(type), + settings->autosave_interval); + + if (!autosave_state.list[i]) + RARCH_WARN("%s\n", msg_hash_to_str(MSG_AUTOSAVE_FAILED)); + } +} + +void autosave_event_deinit(void) +{ + unsigned i; + + for (i = 0; i < autosave_state.num; i++) + autosave_free(autosave_state.list[i]); + + if (autosave_state.list) + free(autosave_state.list); + + autosave_state.list = NULL; + autosave_state.num = 0; +} diff --git a/autosave.h b/autosave.h index 5d95ba9fe1..6734b870d4 100644 --- a/autosave.h +++ b/autosave.h @@ -62,6 +62,10 @@ void lock_autosave(void); **/ void unlock_autosave(void); +void autosave_event_init(void); + +void autosave_event_deinit(void); + #ifdef __cplusplus } #endif diff --git a/command_event.c b/command_event.c index a91fd2cd0d..fb5bae847a 100644 --- a/command_event.c +++ b/command_event.c @@ -20,6 +20,7 @@ #include "command_event.h" #include "audio/audio_driver.h" +#include "autosave.h" #include "general.h" #include "performance.h" #include "dynamic.h" @@ -91,56 +92,6 @@ static void event_init_remote(void) #endif -#if defined(HAVE_THREADS) -static void event_init_autosave(void) -{ - unsigned i; - settings_t *settings = config_get_ptr(); - global_t *global = global_get_ptr(); - - if (settings->autosave_interval < 1 || !global->savefiles) - return; - - if (!(global->autosave.list = (autosave_t**)calloc(global->savefiles->size, - sizeof(*global->autosave.list)))) - return; - - global->autosave.num = global->savefiles->size; - - for (i = 0; i < global->savefiles->size; i++) - { - const char *path = global->savefiles->elems[i].data; - unsigned type = global->savefiles->elems[i].attr.i; - - if (core.retro_get_memory_size(type) <= 0) - continue; - - global->autosave.list[i] = autosave_new(path, - core.retro_get_memory_data(type), - core.retro_get_memory_size(type), - settings->autosave_interval); - - if (!global->autosave.list[i]) - RARCH_WARN("%s\n", msg_hash_to_str(MSG_AUTOSAVE_FAILED)); - } -} - -static void event_deinit_autosave(void) -{ - unsigned i; - global_t *global = global_get_ptr(); - - for (i = 0; i < global->autosave.num; i++) - autosave_free(global->autosave.list[i]); - - if (global->autosave.list) - free(global->autosave.list); - - global->autosave.list = NULL; - global->autosave.num = 0; -} -#endif - static void event_save_files(void) { unsigned i; @@ -1270,13 +1221,13 @@ bool event_command(enum event_command cmd) break; case EVENT_CMD_AUTOSAVE_DEINIT: #ifdef HAVE_THREADS - event_deinit_autosave(); + autosave_event_deinit(); #endif break; case EVENT_CMD_AUTOSAVE_INIT: event_command(EVENT_CMD_AUTOSAVE_DEINIT); #ifdef HAVE_THREADS - event_init_autosave(); + autosave_event_init(); #endif break; case EVENT_CMD_AUTOSAVE_STATE: diff --git a/runloop.c b/runloop.c index 3ec0bcc22b..84caae3094 100644 --- a/runloop.c +++ b/runloop.c @@ -32,6 +32,7 @@ #ifdef HAVE_CHEEVOS #include "cheevos.h" #endif +#include "autosave.h" #include "configuration.h" #include "performance.h" #include "retroarch.h" diff --git a/runloop.h b/runloop.h index 2526b1629f..8c944507b8 100644 --- a/runloop.h +++ b/runloop.h @@ -25,7 +25,6 @@ #include "core_options.h" #include "driver.h" #include "rewind.h" -#include "autosave.h" #include "movie.h" #include "cheats.h" #include "dynamic.h" @@ -228,13 +227,6 @@ typedef struct global bool use; } sram; - /* Autosave support. */ - struct - { - autosave_t **list; - unsigned num; - } autosave; - #ifdef HAVE_NETPLAY /* Netplay. */ struct