From ba7eb0c7b9d93987173780d5b819c7f2ec79b96e Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Thu, 3 Mar 2016 15:53:42 +0500 Subject: Add utility macro to work with thread local storage --- source/blender/blenlib/BLI_threads.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/source/blender/blenlib/BLI_threads.h b/source/blender/blenlib/BLI_threads.h index 6ae833d5ed7..b4a465bbc74 100644 --- a/source/blender/blenlib/BLI_threads.h +++ b/source/blender/blenlib/BLI_threads.h @@ -181,6 +181,27 @@ bool BLI_thread_queue_is_empty(ThreadQueue *queue); void BLI_thread_queue_wait_finish(ThreadQueue *queue); void BLI_thread_queue_nowait(ThreadQueue *queue); + +/* Thread local storage */ + +#if defined(__APPLE__) +# define ThreadLocal(type) pthread_key_t +# define BLI_thread_local_create(name) pthread_key_create(&name, NULL) +# define BLI_thread_local_delete(name) pthread_key_delete(name) +# define BLI_thread_local_get(name) pthread_getspecific(name) +# define BLI_thread_local_set(name, value) pthread_setspecific(name, value) +#else /* defined(__APPLE__) */ +# ifdef _MSC_VER +# define ThreadLocal(type) __declspec(thread) type +# else +# define ThreadLocal(type) __thread type +# endif +# define BLI_thread_local_create(name) +# define BLI_thread_local_delete(name) +# define BLI_thread_local_get(name) name +# define BLI_thread_local_set(name, value) name = value +#endif /* defined(__APPLE__) */ + #ifdef __cplusplus } #endif -- cgit v1.2.3