From d8796732aabf5a966a2413ce6f66eb8a440d0141 Mon Sep 17 00:00:00 2001 From: Sven <40953353+RetroSven@users.noreply.github.com> Date: Tue, 11 Sep 2018 13:29:20 -0400 Subject: [PATCH] provide a means for cores to coordinate with the frontend when shutting down multiple threads gracefully --- dynamic.c | 21 ++++++++++++++++++--- libretro-common/include/libretro.h | 14 ++++++++++++++ retroarch.h | 2 -- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/dynamic.c b/dynamic.c index 462628eb5d..73e593298d 100644 --- a/dynamic.c +++ b/dynamic.c @@ -1042,6 +1042,16 @@ static void core_performance_counter_stop(struct retro_perf_counter *perf) perf->total += cpu_features_get_perf_counter() - perf->start; } +bool rarch_clear_all_thread_waits(unsigned clear_threads, void *data) +{ + if ( clear_threads > 0) + audio_driver_start(false) ; + else + audio_driver_stop() ; + + return true ; +} + /** * rarch_environment_cb: * @cmd : Identifier of command. @@ -1833,8 +1843,8 @@ bool rarch_environment_cb(unsigned cmd, void *data) int* result_p = (int*)data; *result_p = result; } + break; } - break; case RETRO_ENVIRONMENT_GET_MIDI_INTERFACE: { @@ -1849,16 +1859,21 @@ bool rarch_environment_cb(unsigned cmd, void *data) midi_interface->write = midi_driver_write; midi_interface->flush = midi_driver_flush; } + break; } - break; case RETRO_ENVIRONMENT_GET_FASTFORWARDING: { extern bool runloop_fastmotion; *(bool *)data = runloop_fastmotion; + break; } - break; + case RETRO_ENVIRONMENT_GET_CLEAR_ALL_THREAD_WAITS_CB: + { + *(retro_environment_t *)data = rarch_clear_all_thread_waits; + break; + } default: RARCH_LOG("Environ UNSUPPORTED (#%u).\n", cmd); diff --git a/libretro-common/include/libretro.h b/libretro-common/include/libretro.h index 78e67a0781..bd95d508f6 100644 --- a/libretro-common/include/libretro.h +++ b/libretro-common/include/libretro.h @@ -1195,6 +1195,20 @@ struct retro_led_interface * fastforwarding mode. */ +#define RETRO_ENVIRONMENT_SET_SAVE_STATE_IN_BACKGROUND (50 | RETRO_ENVIRONMENT_EXPERIMENTAL) + /* bool * -- + * Boolean value that tells the front end to save states in the + * background or not. + */ + +#define RETRO_ENVIRONMENT_GET_CLEAR_ALL_THREAD_WAITS_CB (51 | RETRO_ENVIRONMENT_EXPERIMENTAL) + /* retro_environment_t * -- + * Provides the callback to the frontend method which will cancel + * all currently waiting threads. Used when coordination is needed + * between the core and the frontend to gracefully stop all threads. + */ + + /* Retrieves the current state of the MIDI input. * Returns true if it's enabled, false otherwise. */ typedef bool (RETRO_CALLCONV *retro_midi_input_enabled_t)(void); diff --git a/retroarch.h b/retroarch.h index dda1628c29..46d882deed 100644 --- a/retroarch.h +++ b/retroarch.h @@ -33,8 +33,6 @@ RETRO_BEGIN_DECLS -#define RETRO_ENVIRONMENT_SET_SAVE_STATE_IN_BACKGROUND RETRO_ENVIRONMENT_PRIVATE+1 - enum rarch_ctl_state { RARCH_CTL_NONE = 0,