diff --git a/retroarch.c b/retroarch.c index f544a67ff2..558172462b 100644 --- a/retroarch.c +++ b/retroarch.c @@ -42,7 +42,7 @@ #include #include #include - +#include #include #ifdef HAVE_CONFIG_H @@ -1108,6 +1108,10 @@ bool rarch_ctl(enum rarch_ctl_state state, void *data) static bool rarch_ips_pref = false; static bool rarch_patch_blocked = false; settings_t *settings = config_get_ptr(); +#ifdef HAVE_THREADS + static sthread_tls_t rarch_tls; + const void *MAGIC_POINTER = (void*)0xB16B00B5; +#endif switch(state) { @@ -1218,9 +1222,17 @@ bool rarch_ctl(enum rarch_ctl_state state, void *data) path_deinit_savefile(); rarch_ctl(RARCH_CTL_UNSET_INITED, NULL); + +#ifdef HAVE_THREADS + sthread_tls_delete(&rarch_tls); +#endif break; case RARCH_CTL_INIT: rarch_ctl(RARCH_CTL_DEINIT, NULL); +#ifdef HAVE_THREADS + sthread_tls_create(&rarch_tls); + sthread_tls_set(&rarch_tls, MAGIC_POINTER); +#endif retroarch_init_state(); { unsigned i; @@ -1306,6 +1318,12 @@ bool rarch_ctl(enum rarch_ctl_state state, void *data) command_event(CMD_EVENT_OVERLAY_INIT, NULL); #endif break; + case RARCH_CTL_IS_MAIN_THREAD: +#ifdef HAVE_THREADS + return sthread_tls_get(&rarch_tls) == MAGIC_POINTER; +#else + return true; +#endif case RARCH_CTL_NONE: default: return false; diff --git a/retroarch.h b/retroarch.h index e8fb374033..15799c69fd 100644 --- a/retroarch.h +++ b/retroarch.h @@ -106,8 +106,9 @@ enum rarch_ctl_state /* Username */ RARCH_CTL_HAS_SET_USERNAME, RARCH_CTL_USERNAME_SET, - RARCH_CTL_USERNAME_UNSET + RARCH_CTL_USERNAME_UNSET, + RARCH_CTL_IS_MAIN_THREAD }; enum rarch_capabilities