Add utility macro to work with thread local storage
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user