diff options
Diffstat (limited to 'pixman/pixman/pixman-compiler.h')
-rw-r--r-- | pixman/pixman/pixman-compiler.h | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/pixman/pixman/pixman-compiler.h b/pixman/pixman/pixman-compiler.h index 9647dbb48..a4e3f88bc 100644 --- a/pixman/pixman/pixman-compiler.h +++ b/pixman/pixman/pixman-compiler.h @@ -69,3 +69,63 @@ # define PIXMAN_EXPORT #endif +/* TLS */ +#if defined(TOOLCHAIN_SUPPORTS__THREAD) + +# define PIXMAN_DEFINE_THREAD_LOCAL(type, name) \ + static __thread type name +# define PIXMAN_GET_THREAD_LOCAL(name) \ + (&name) + +#elif defined(_MSC_VER) + +# define PIXMAN_DEFINE_THREAD_LOCAL(type, name) \ + static __declspec(thread) type name +# define PIXMAN_GET_THREAD_LOCAL(name) \ + (&name) + +#elif defined(HAVE_PTHREAD_SETSPECIFIC) + +#include <pthread.h> + +# define PIXMAN_DEFINE_THREAD_LOCAL(type, name) \ + static pthread_once_t tls_ ## name ## _once_control = PTHREAD_ONCE_INIT; \ + static pthread_key_t tls_ ## name ## _key; \ + \ + static void \ + tls_ ## name ## _make_key (void) \ + { \ + pthread_key_create (&tls_ ## name ## _key, NULL); \ + } \ + \ + static type * \ + tls_ ## name ## _alloc (key) \ + { \ + type *value = malloc (sizeof (type)); \ + if (value) \ + pthread_setspecific (key, value); \ + return value; \ + } \ + \ + static force_inline type * \ + tls_ ## name ## _get (key) \ + { \ + type *value = NULL; \ + if (pthread_once (&tls_ ## name ## _once_control, \ + tls_ ## name ## _make_key) == 0) \ + { \ + value = pthread_getspecific (tls_ ## name ## _key); \ + if (!value) \ + value = tls_ ## name ## _alloc (key); \ + } \ + return value; \ + } + +# define PIXMAN_GET_THREAD_LOCAL(name) \ + tls_ ## name ## _get (tls_ ## name ## _key) + +#else + +# error "Unknown thread local support for this system" + +#endif |