diff --git a/command.c b/command.c index 01aa047bee..c974a29e14 100644 --- a/command.c +++ b/command.c @@ -2063,7 +2063,10 @@ bool command_event(enum event_command cmd, void *data) case CMD_EVENT_AUTOSAVE_INIT: command_event(CMD_EVENT_AUTOSAVE_DEINIT, NULL); #ifdef HAVE_THREADS - return autosave_init(); + if (autosave_init()) + runloop_set(RUNLOOP_ACTION_AUTOSAVE); + else + runloop_unset(RUNLOOP_ACTION_AUTOSAVE); #else break; #endif diff --git a/runloop.c b/runloop.c index a949967756..487e9460ef 100644 --- a/runloop.c +++ b/runloop.c @@ -132,6 +132,7 @@ static bool runloop_perfcnt_enable = false; static bool runloop_overrides_active = false; static bool runloop_game_options_active = false; static bool runloop_missing_bios = false; +static bool runloop_autosave = false; static retro_time_t frame_limit_minimum_time = 0.0; static retro_time_t frame_limit_last_time = 0.0; @@ -392,6 +393,7 @@ bool runloop_ctl(enum runloop_ctl_state state, void *data) runloop_paused = false; runloop_slowmotion = false; runloop_overrides_active = false; + runloop_autosave = false; runloop_ctl(RUNLOOP_CTL_FRAME_TIME_FREE, NULL); break; case RUNLOOP_CTL_GLOBAL_FREE: @@ -1040,6 +1042,30 @@ static enum runloop_state runloop_check_state( #define runloop_netplay_pause() ((void)0) #endif +void runloop_set(enum runloop_action action) +{ + switch (action) + { + case RUNLOOP_ACTION_AUTOSAVE: + runloop_autosave = true; + break; + case RUNLOOP_ACTION_NONE: + break; + } +} + +void runloop_unset(enum runloop_action action) +{ + switch (action) + { + case RUNLOOP_ACTION_AUTOSAVE: + runloop_autosave = false; + break; + case RUNLOOP_ACTION_NONE: + break; + } +} + /** * runloop_iterate: * @@ -1133,7 +1159,8 @@ int runloop_iterate(unsigned *sleep_ms) break; } - autosave_lock(); + if (runloop_autosave) + autosave_lock(); bsv_movie_set_frame_start(); @@ -1178,7 +1205,8 @@ int runloop_iterate(unsigned *sleep_ms) bsv_movie_set_frame_end(); - autosave_unlock(); + if (runloop_autosave) + autosave_unlock(); if (!settings->floats.fastforward_ratio) return 0; diff --git a/runloop.h b/runloop.h index 2ed66e0402..f2899307f2 100644 --- a/runloop.h +++ b/runloop.h @@ -28,6 +28,12 @@ RETRO_BEGIN_DECLS +enum runloop_action +{ + RUNLOOP_ACTION_NONE = 0, + RUNLOOP_ACTION_AUTOSAVE +}; + enum runloop_ctl_state { RUNLOOP_CTL_NONE = 0, @@ -209,6 +215,10 @@ void runloop_get_status(bool *is_paused, bool *is_idle, bool *is_slowmotion, bool runloop_ctl(enum runloop_ctl_state state, void *data); +void runloop_set(enum runloop_action action); + +void runloop_unset(enum runloop_action action); + rarch_system_info_t *runloop_get_system_info(void); RETRO_END_DECLS