From 330a8d7594d262750c0801cc1379748c47367848 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Higor=20Eur=C3=ADpedes?= Date: Mon, 17 Oct 2016 21:21:51 -0300 Subject: [PATCH] Make thread local storage optional --- Makefile.common | 6 +++++- libretro-common/include/rthreads/rthreads.h | 5 +++++ libretro-common/rthreads/rthreads.c | 2 ++ qb/config.libs.sh | 8 ++++++++ qb/config.params.sh | 3 ++- retroarch.c | 8 ++++---- 6 files changed, 26 insertions(+), 6 deletions(-) diff --git a/Makefile.common b/Makefile.common index 76ed5fe6af..b04e7e22dc 100644 --- a/Makefile.common +++ b/Makefile.common @@ -575,6 +575,10 @@ ifeq ($(HAVE_THREADS), 1) endif endif +ifeq ($(HAVE_THREAD_STORAGE), 1) + DEFINES += -DHAVE_THREAD_STORAGE +endif + ifeq ($(HAVE_WAYLAND), 1) OBJ += gfx/drivers_context/wayland_ctx.o DEFINES += $(WAYLAND_CFLAGS) @@ -1064,7 +1068,7 @@ OBJ += $(ZLIB_OBJS) endif endif -# Video4Linux 2 +# Video4Linux 2 ifeq ($(HAVE_V4L2),1) OBJ += camera/drivers/video4linux2.o diff --git a/libretro-common/include/rthreads/rthreads.h b/libretro-common/include/rthreads/rthreads.h index 86d1fde8b0..9af41fd301 100644 --- a/libretro-common/include/rthreads/rthreads.h +++ b/libretro-common/include/rthreads/rthreads.h @@ -35,7 +35,10 @@ RETRO_BEGIN_DECLS typedef struct sthread sthread_t; typedef struct slock slock_t; typedef struct scond scond_t; + +#ifdef HAVE_THREAD_STORAGE typedef unsigned sthread_tls_t; +#endif /** * sthread_create: @@ -179,6 +182,7 @@ int scond_broadcast(scond_t *cond); **/ void scond_signal(scond_t *cond); +#ifdef HAVE_THREAD_STORAGE /** * @brief Creates a thread local storage key * @@ -218,6 +222,7 @@ void *sthread_tls_get(sthread_tls_t *tls); * @return whether the operation suceeded or not */ bool sthread_tls_set(sthread_tls_t *tls, const void *data); +#endif RETRO_END_DECLS diff --git a/libretro-common/rthreads/rthreads.c b/libretro-common/rthreads/rthreads.c index aca3bd1e88..f8ea548be9 100644 --- a/libretro-common/rthreads/rthreads.c +++ b/libretro-common/rthreads/rthreads.c @@ -475,6 +475,7 @@ bool scond_wait_timeout(scond_t *cond, slock_t *lock, int64_t timeout_us) #endif } +#ifdef HAVE_THREAD_STORAGE bool sthread_tls_create(sthread_tls_t *tls) { #ifdef USE_WIN32_THREADS @@ -510,3 +511,4 @@ bool sthread_tls_set(sthread_tls_t *tls, const void *data) return pthread_setspecific(*tls, data) == 0; #endif } +#endif diff --git a/qb/config.libs.sh b/qb/config.libs.sh index 3cf24ece08..c60c9a0218 100644 --- a/qb/config.libs.sh +++ b/qb/config.libs.sh @@ -150,9 +150,17 @@ fi if [ "$OS" = 'Win32' ]; then HAVE_THREADS=yes + HAVE_THREAD_STORAGE=yes HAVE_DYLIB=yes else check_lib THREADS "$PTHREADLIB" pthread_create + + if [ "$HAVE_THREADS" = 'yes' ]; then + check_lib THREAD_STORAGE "$PTHREADLIB" pthread_key_create + else + HAVE_THREAD_STORAGE=no + fi + check_lib DYLIB "$DYLIB" dlopen fi diff --git a/qb/config.params.sh b/qb/config.params.sh index a5d1d57481..61d5a41861 100644 --- a/qb/config.params.sh +++ b/qb/config.params.sh @@ -1,6 +1,6 @@ HAVE_LIBRETRODB=yes # Libretrodb support HAVE_RGUI=yes # RGUI menu -HAVE_MATERIALUI=auto # MaterialUI menu +HAVE_MATERIALUI=auto # MaterialUI menu HAVE_XMB=auto # XMB menu HAVE_ZARCH=no # Zarch menu HAVE_NUKLEAR=no # Nuklear menu @@ -20,6 +20,7 @@ HAVE_MAN_DIR= # Manpage install directory HAVE_OPENGLES_LIBS= # Link flags for custom GLES library HAVE_OPENGLES_CFLAGS= # C-flags for custom GLES library HAVE_THREADS=auto # Threading support +HAVE_THREAD_STORAGE=auto # Thread Local Storage support HAVE_FFMPEG=auto # FFmpeg recording support C89_FFMPEG=no HAVE_SSA=auto # SSA/ASS for FFmpeg subtitle support diff --git a/retroarch.c b/retroarch.c index 558172462b..2c8effecb5 100644 --- a/retroarch.c +++ b/retroarch.c @@ -1108,7 +1108,7 @@ 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 +#ifdef HAVE_THREAD_STORAGE static sthread_tls_t rarch_tls; const void *MAGIC_POINTER = (void*)0xB16B00B5; #endif @@ -1223,13 +1223,13 @@ bool rarch_ctl(enum rarch_ctl_state state, void *data) rarch_ctl(RARCH_CTL_UNSET_INITED, NULL); -#ifdef HAVE_THREADS +#ifdef HAVE_THREAD_STORAGE sthread_tls_delete(&rarch_tls); #endif break; case RARCH_CTL_INIT: rarch_ctl(RARCH_CTL_DEINIT, NULL); -#ifdef HAVE_THREADS +#ifdef HAVE_THREAD_STORAGE sthread_tls_create(&rarch_tls); sthread_tls_set(&rarch_tls, MAGIC_POINTER); #endif @@ -1319,7 +1319,7 @@ bool rarch_ctl(enum rarch_ctl_state state, void *data) #endif break; case RARCH_CTL_IS_MAIN_THREAD: -#ifdef HAVE_THREADS +#ifdef HAVE_THREAD_STORAGE return sthread_tls_get(&rarch_tls) == MAGIC_POINTER; #else return true;