diff --git a/content.h b/content.h index e2b8ee6ed9..fb979003b6 100644 --- a/content.h +++ b/content.h @@ -51,8 +51,8 @@ bool content_load_state(const char* path, bool load_to_backup_buffer, bool autol /* Save a state from memory to disk. */ bool content_save_state(const char *path, bool save_to_disk, bool autosave); -/* Returns true if a save state task is in progress */ -bool content_save_state_in_progress(void); +/* Waits for any in-progress save state tasks to finish */ +void content_wait_for_save_state_task(void); /* Copy a save state. */ bool content_rename_state(const char *origin, const char *dest); diff --git a/libretro-common/queues/task_queue.c b/libretro-common/queues/task_queue.c index 18029ce78c..58ede3e805 100644 --- a/libretro-common/queues/task_queue.c +++ b/libretro-common/queues/task_queue.c @@ -235,7 +235,7 @@ static void retro_task_regular_gather(void) static void retro_task_regular_wait(retro_task_condition_fn_t cond, void* data) { - while (tasks_running.front && (!cond || cond(data))) + while ((tasks_running.front && !tasks_running.front->when) && (!cond || cond(data))) retro_task_regular_gather(); } @@ -420,10 +420,9 @@ static void retro_task_threaded_wait(retro_task_condition_fn_t cond, void* data) retro_task_threaded_gather(); slock_lock(running_lock); - wait = (tasks_running.front) && - (!cond || cond(data)); + wait = (tasks_running.front && !tasks_running.front->when); slock_unlock(running_lock); - } while (wait); + } while (wait && (!cond || cond(data))); } static void retro_task_threaded_reset(void) diff --git a/retroarch.c b/retroarch.c index 8cdb46826f..55f38feec3 100644 --- a/retroarch.c +++ b/retroarch.c @@ -37605,8 +37605,7 @@ bool retroarch_main_quit(void) /* If any save states are in progress, wait * until all tasks are complete (otherwise * save state file may be truncated) */ - if (content_save_state_in_progress()) - task_queue_wait(NULL, NULL); + content_wait_for_save_state_task(); #ifdef HAVE_CONFIGFILE if (p_rarch->runloop_overrides_active) diff --git a/tasks/task_save.c b/tasks/task_save.c index 17bdc390a5..dcf342cd8c 100644 --- a/tasks/task_save.c +++ b/tasks/task_save.c @@ -1372,7 +1372,7 @@ static bool task_save_state_finder(retro_task_t *task, void *user_data) } /* Returns true if a save state task is in progress */ -bool content_save_state_in_progress(void) +static bool content_save_state_in_progress(void* data) { task_finder_data_t find_data; @@ -1385,6 +1385,11 @@ bool content_save_state_in_progress(void) return false; } +void content_wait_for_save_state_task(void) +{ + task_queue_wait(content_save_state_in_progress, NULL); +} + /** * content_load_state: * @path : path that state will be loaded from.