LIBRETRO: fix emu thread deinit

This commit is contained in:
Giovanni Cascione 2023-04-20 01:24:54 +02:00
parent a448f6ce34
commit 6cf91e9438
2 changed files with 18 additions and 21 deletions

View File

@ -78,7 +78,6 @@ static void retro_wrap_emulator(void) {
status &= ~EMU_EXITED;
scummvm_res = retro_run_emulator();
status |= EMU_EXITED;
retro_exit_to_main_thread();
}
@ -106,6 +105,8 @@ static void retro_free_emu_thread() {
}
void retro_switch_to_emu_thread() {
if (retro_emu_thread_exited() || !retro_emu_thread_initialized())
return;
#ifdef USE_LIBCO
co_switch(emu_thread);
#else
@ -169,11 +170,8 @@ bool retro_init_emu_thread(void) {
}
void retro_deinit_emu_thread() {
if (!retro_emu_thread_initialized())
return;
if (!retro_current_thread_is_main())
retro_switch_to_main_thread();
retro_free_emu_thread();
if (retro_emu_thread_initialized())
retro_free_emu_thread();
}
int retro_get_scummvm_res() {

View File

@ -671,15 +671,6 @@ bool retro_load_game_special(unsigned game_type, const struct retro_game_info *i
}
void retro_run(void) {
if (retro_emu_thread_exited())
retro_deinit_emu_thread();
if (!retro_emu_thread_initialized()) {
environ_cb(RETRO_ENVIRONMENT_SHUTDOWN, NULL);
return;
}
bool updated = false;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) && updated){
update_variables();
@ -763,6 +754,14 @@ void retro_run(void) {
if (!skip_frame)
retro_switch_to_emu_thread();
if (retro_emu_thread_exited())
retro_deinit_emu_thread();
if (!retro_emu_thread_initialized()) {
environ_cb(RETRO_ENVIRONMENT_SHUTDOWN, NULL);
return;
}
/* Retrieve audio */
samples_count = 0;
if (audio_video_enable & 2) {
@ -799,13 +798,13 @@ void retro_run(void) {
}
void retro_unload_game(void) {
if (!retro_emu_thread_initialized())
return;
while (!retro_emu_thread_exited()) {
retroQuit();
retro_switch_to_emu_thread();
if (retro_emu_thread_initialized()) {
while (!retro_emu_thread_exited()) {
retroQuit();
retro_switch_to_emu_thread();
}
retro_deinit_emu_thread();
}
retro_deinit_emu_thread();
if (retro_get_scummvm_res() == Common::kNoError)
log_cb(RETRO_LOG_INFO, "ScummVM exited successfully.\n");