(retroarch.c) Add RARCH_CTL_IS_MAIN_THREAD

This commit is contained in:
Higor Eurípedes 2016-10-17 20:50:19 -03:00
parent 471ff4a999
commit dd36cff174
2 changed files with 21 additions and 2 deletions

View File

@ -42,7 +42,7 @@
#include <retro_stat.h> #include <retro_stat.h>
#include <retro_assert.h> #include <retro_assert.h>
#include <retro_miscellaneous.h> #include <retro_miscellaneous.h>
#include <rthreads/rthreads.h>
#include <features/features_cpu.h> #include <features/features_cpu.h>
#ifdef HAVE_CONFIG_H #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_ips_pref = false;
static bool rarch_patch_blocked = false; static bool rarch_patch_blocked = false;
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
#ifdef HAVE_THREADS
static sthread_tls_t rarch_tls;
const void *MAGIC_POINTER = (void*)0xB16B00B5;
#endif
switch(state) switch(state)
{ {
@ -1218,9 +1222,17 @@ bool rarch_ctl(enum rarch_ctl_state state, void *data)
path_deinit_savefile(); path_deinit_savefile();
rarch_ctl(RARCH_CTL_UNSET_INITED, NULL); rarch_ctl(RARCH_CTL_UNSET_INITED, NULL);
#ifdef HAVE_THREADS
sthread_tls_delete(&rarch_tls);
#endif
break; break;
case RARCH_CTL_INIT: case RARCH_CTL_INIT:
rarch_ctl(RARCH_CTL_DEINIT, NULL); 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(); retroarch_init_state();
{ {
unsigned i; unsigned i;
@ -1306,6 +1318,12 @@ bool rarch_ctl(enum rarch_ctl_state state, void *data)
command_event(CMD_EVENT_OVERLAY_INIT, NULL); command_event(CMD_EVENT_OVERLAY_INIT, NULL);
#endif #endif
break; 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: case RARCH_CTL_NONE:
default: default:
return false; return false;

View File

@ -106,8 +106,9 @@ enum rarch_ctl_state
/* Username */ /* Username */
RARCH_CTL_HAS_SET_USERNAME, RARCH_CTL_HAS_SET_USERNAME,
RARCH_CTL_USERNAME_SET, RARCH_CTL_USERNAME_SET,
RARCH_CTL_USERNAME_UNSET RARCH_CTL_USERNAME_UNSET,
RARCH_CTL_IS_MAIN_THREAD
}; };
enum rarch_capabilities enum rarch_capabilities