From b56c33a260972dc4854dc18ce772336610544360 Mon Sep 17 00:00:00 2001 From: jp9000 Date: Mon, 25 Dec 2017 12:01:10 -0800 Subject: [PATCH] libobs/util: Add THREAD_LOCAL macro Adds a thread local storage macro to declare thread local storage independent of platform. --- libobs/graphics/graphics.c | 6 +----- libobs/util/profiler.c | 9 ++------- libobs/util/threading.h | 6 ++++++ 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/libobs/graphics/graphics.c b/libobs/graphics/graphics.c index 00c1a8795..b6f5bd070 100644 --- a/libobs/graphics/graphics.c +++ b/libobs/graphics/graphics.c @@ -28,11 +28,7 @@ #include "effect-parser.h" #include "effect.h" -#ifdef _MSC_VER -static __declspec(thread) graphics_t *thread_graphics = NULL; -#else /* assume GCC or that other compiler we dare not mention */ -static __thread graphics_t *thread_graphics = NULL; -#endif +static THREAD_LOCAL graphics_t *thread_graphics = NULL; static inline bool gs_obj_valid(const void *obj, const char *f, const char *name) diff --git a/libobs/util/profiler.c b/libobs/util/profiler.c index d82c4fdea..9b57f2c72 100644 --- a/libobs/util/profiler.c +++ b/libobs/util/profiler.c @@ -260,13 +260,8 @@ static bool enabled = false; static pthread_mutex_t root_mutex = PTHREAD_MUTEX_INITIALIZER; static DARRAY(profile_root_entry) root_entries; -#ifdef _MSC_VER -static __declspec(thread) profile_call *thread_context = NULL; -static __declspec(thread) bool thread_enabled = true; -#else -static __thread profile_call *thread_context = NULL; -static __thread bool thread_enabled = true; -#endif +static THREAD_LOCAL profile_call *thread_context = NULL; +static THREAD_LOCAL bool thread_enabled = true; void profiler_start(void) { diff --git a/libobs/util/threading.h b/libobs/util/threading.h index 50212921d..0ae27a21b 100644 --- a/libobs/util/threading.h +++ b/libobs/util/threading.h @@ -78,6 +78,12 @@ EXPORT int os_sem_wait(os_sem_t *sem); EXPORT void os_set_thread_name(const char *name); +#ifdef _MSC_VER +#define THREAD_LOCAL __declspec(thread) +#else +#define THREAD_LOCAL __thread +#endif + #ifdef __cplusplus }