diff --git a/src/osd/libretro/libretro-internal/libretro.cpp b/src/osd/libretro/libretro-internal/libretro.cpp index c392c54f741d3..5e074b1d4d8fa 100755 --- a/src/osd/libretro/libretro-internal/libretro.cpp +++ b/src/osd/libretro/libretro-internal/libretro.cpp @@ -50,6 +50,7 @@ static char option_joystick_deadzone[50]; static char option_joystick_saturation[50]; static char option_mame_4way[50]; static char option_rotation_mode[50]; +static char option_thread_mode[50]; static char option_renderer[50]; static char option_res[50]; static char option_overclock[50]; @@ -199,6 +200,7 @@ void retro_set_environment(retro_environment_t cb) sprintf(option_joystick_saturation, "%s_%s", core, "joystick_saturation"); sprintf(option_mame_4way, "%s_%s", core, "mame_4way_enable"); sprintf(option_rotation_mode, "%s_%s", core, "rotation_mode"); + sprintf(option_thread_mode, "%s_%s", core, "thread_mode"); sprintf(option_renderer, "%s_%s", core, "alternate_renderer"); sprintf(option_res, "%s_%s", core, "altres"); sprintf(option_overclock, "%s_%s", core, "cpu_overclock"); @@ -226,6 +228,7 @@ void retro_set_environment(retro_environment_t cb) { option_joystick_saturation, "Joystick Saturation; 1.00|0.05|0.10|0.15|0.20|0.25|0.30|0.35|0.40|0.45|0.50|0.55|0.60|0.65|0.70|0.75|0.80|0.85|0.90|0.95|1.00" }, { option_mame_4way, "Joystick 4-way Simulation; disabled|4way|strict|qbert"}, { option_rotation_mode, "Rotation Mode; libretro|internal|none" }, + { option_thread_mode, "Enable Threads(restart); enabled|disabled" }, { option_renderer, "Alternate Renderer; disabled|enabled" }, { option_res, "Alternate Renderer Resolution; 640x480|640x360|800x600|800x450|960x720|960x540|1024x768|1024x576|1280x960|1280x720|1600x1200|1600x900|1440x1080|1920x1080|1920x1440|2560x1440|2880x2160|3840x2160" }, { option_overclock, "Main CPU Overclock; default|30|31|32|33|34|35|36|37|38|39|40|41|42|43|44|45|46|47|48|49|50|51|52|53|54|55|60|65|70|75|80|85|90|95|100|105|110|115|120|125|130|135|140|145|150" }, @@ -397,6 +400,19 @@ static void check_variables(void) rotation_mode = 0; } + var.key = option_thread_mode; + var.value = NULL; + + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { + if (!strcmp(var.value, "enabled")) + thread_mode = 1; + else if (!strcmp(var.value, "disabled")) + thread_mode = 0; + else + thread_mode = 0; + } + var.key = option_renderer; var.value = NULL; diff --git a/src/osd/libretro/libretro-internal/libretro_shared.h b/src/osd/libretro/libretro-internal/libretro_shared.h index b41fbfb057019..1190d811c5209 100644 --- a/src/osd/libretro/libretro-internal/libretro_shared.h +++ b/src/osd/libretro/libretro-internal/libretro_shared.h @@ -106,6 +106,7 @@ extern float retro_aspect; extern float retro_fps; extern float view_aspect; extern int rotation_mode; +extern int thread_mode; static const char core[] = "mame"; /* libretro callbacks */ diff --git a/src/osd/libretro/libretro-internal/retro_init.cpp b/src/osd/libretro/libretro-internal/retro_init.cpp index fd308889e0f0e..587580d848b72 100755 --- a/src/osd/libretro/libretro-internal/retro_init.cpp +++ b/src/osd/libretro/libretro-internal/retro_init.cpp @@ -71,7 +71,7 @@ static bool arcade = false; static int FirstTimeUpdate = 1; int rotation_mode = 0; int rotation_allow = 0; - +int thread_mode = 0; // rom file name and path char g_rom_dir[1024]; char mediaType[10]; diff --git a/src/osd/osdsync.cpp b/src/osd/osdsync.cpp index 464a1892ed92e..1e68333e88b54 100644 --- a/src/osd/osdsync.cpp +++ b/src/osd/osdsync.cpp @@ -61,6 +61,9 @@ #define end_timing(v) do { } while (0) #endif +#if defined(__LIBRETRO__) +extern int thread_mode; +#endif template static void spin_while(const volatile _AtomType * volatile atom, const _MainType val, const osd_ticks_t timeout, const int invert = 0) { @@ -88,6 +91,12 @@ static void spin_while_not(const volatile _AtomType * volatile atom, const _Main int osd_get_num_processors(bool heavy_mt) { + +#if defined(__LIBRETRO__) + if(!thread_mode) + return 1; +#endif + #if defined(SDLMAME_EMSCRIPTEN) // multithreading is not supported at this time return 1; @@ -280,6 +289,11 @@ osd_work_queue *osd_work_queue_alloc(int flags) threadnum = 0; #endif +#if defined(__LIBRETRO__) + if(!thread_mode) + threadnum = 0; +#endif + // clamp to the maximum queue->threads = std::min(threadnum, WORK_MAX_THREADS);