2 * Written by Josh Dybnis and released to the public domain, as explained at
3 * http://creativecommons.org/licenses/publicdomain
5 * A platform independant wrapper around thread-local storage. On platforms that don't support
6 * __thread variables (e.g. Mac OS X), we have to use the pthreads library for thread-local storage
11 #ifdef __ELF__ // use gcc thread-local storage (i.e. __thread variables)
12 #define DECLARE_THREAD_LOCAL(name, type) __thread type name
13 #define INIT_THREAD_LOCAL(name)
14 #define SET_THREAD_LOCAL(name, value) name = value
15 #define LOCALIZE_THREAD_LOCAL(name, type)
21 #define DECLARE_THREAD_LOCAL(name, type) pthread_key_t name##_KEY
23 #define INIT_THREAD_LOCAL(name) \
25 if (pthread_key_create(&name##_KEY, NULL) != 0) { assert(FALSE); } \
28 #define SET_THREAD_LOCAL(name, value) pthread_setspecific(name##_KEY, (void *)(size_t)value);
30 #define LOCALIZE_THREAD_LOCAL(name, type) type name = (type)(size_t)pthread_getspecific(name##_KEY)