+ xpthread_setspecific(NAME##_key, value); \
+ } \
+ return value; \
+ }
+#define DECLARE_EXTERN_PER_THREAD_DATA(TYPE, NAME) \
+ typedef TYPE NAME##_type; \
+ static pthread_key_t NAME##_key; \
+ \
+ static inline NAME##_type * \
+ NAME##_get_unsafe(void) \
+ { \
+ return pthread_getspecific(NAME##_key); \
+ } \
+ \
+ NAME##_type *NAME##_get(void);
+#define DEFINE_EXTERN_PER_THREAD_DATA(NAME, ...) \
+ static void \
+ NAME##_once_init(void) \
+ { \
+ if (pthread_key_create(&NAME##_key, free)) { \
+ abort(); \
+ } \
+ } \
+ \
+ NAME##_type * \
+ NAME##_get(void) \
+ { \
+ static pthread_once_t once = PTHREAD_ONCE_INIT; \
+ NAME##_type *value; \
+ \
+ pthread_once(&once, NAME##_once_init); \
+ value = NAME##_get_unsafe(); \
+ if (!value) { \
+ static const NAME##_type initial_value = __VA_ARGS__; \
+ \
+ value = xmalloc(sizeof *value); \
+ *value = initial_value; \
+ xpthread_setspecific(NAME##_key, value); \