55 #ifndef ROOT_ThreadLocalStorage
56 #define ROOT_ThreadLocalStorage
62 #ifndef ROOT_RConfigure
63 #include "RConfigure.h"
66 #if defined(R__MACOSX)
67 # if defined(__clang__) && defined(MAC_OS_X_VERSION_10_7) && (defined(__x86_64__) || defined(__i386__))
68 # define R__HAS___THREAD
69 # elif !defined(R__HAS_PTHREAD)
70 # define R__HAS_PTHREAD
73 #if defined(R__LINUX) || defined(R__AIX)
74 # define R__HAS___THREAD
76 #if defined(R__SOLARIS) && !defined(R__HAS_PTHREAD)
77 # define R__HAS_PTHREAD
80 # define R__HAS_DECLSPEC_THREAD
83 #if __cplusplus >= 201103L
86 # if defined(__clang__)
88 # if __has_feature(cxx_thread_local)
93 # define R__HAS_THREAD_LOCAL
95 # define R__HAS___THREAD
98 # elif defined(__INTEL_COMPILER)
99 # define R__HAS__THREAD
101 # elif defined(__GNUG__) && (__GNUC__ <= 4 && __GNUC_MINOR__ < 8)
103 # define R__HAS___THREAD
105 # define R__HAS_THREAD_LOCAL
118 # define TTHREAD_TLS(type) static type
119 # define TTHREAD_TLS_ARRAY(type,size,name) static type name[size]
120 # define TTHREAD_TLS_PTR(name) &name
122 #elif defined(R__HAS_THREAD_LOCAL)
124 # define TTHREAD_TLS(type) thread_local type
125 # define TTHREAD_TLS_ARRAY(type,size,name) thread_local type name[size]
126 # define TTHREAD_TLS_PTR(name) &name
128 # define TTHREAD_TLS_DECL(type, name) thread_local type name
129 # define TTHREAD_TLS_DECL_ARG(type, name, arg) thread_local type name(arg)
130 # define TTHREAD_TLS_DECL_ARG2(type, name, arg1, arg2) thread_local type name(arg1,arg2)
132 #elif defined(R__HAS___THREAD)
134 # define TTHREAD_TLS(type) static __thread type
135 # define TTHREAD_TLS_ARRAY(type,size,name) static __thread type name[size]
136 # define TTHREAD_TLS_PTR(name) &name
138 #elif defined(R__HAS_DECLSPEC_THREAD)
140 # define TTHREAD_TLS(type) static __declspec(thread) type
141 # define TTHREAD_TLS_ARRAY(type,size,name) static __declspec(thread) type name[size]
142 # define TTHREAD_TLS_PTR(name) &name
144 #elif defined(R__HAS_PTHREAD)
149 template <
typename type>
class TThreadTLSWrapper
155 static void key_delete(
void *arg) {
162 TThreadTLSWrapper() : fInitValue() {
164 pthread_key_create(&(fKey), key_delete);
167 TThreadTLSWrapper(
const type &value) : fInitValue(value) {
169 pthread_key_create(&(fKey), key_delete);
172 ~TThreadTLSWrapper() {
173 pthread_key_delete(fKey);
177 void *ptr = pthread_getspecific(fKey);
179 ptr =
new type(fInitValue);
181 (
void) pthread_setspecific(fKey, ptr);
198 template <
typename type,
int size>
class TThreadTLSArrayWrapper
203 static void key_delete(
void *arg) {
205 delete [] (
type*)(arg);
210 TThreadTLSArrayWrapper() {
212 pthread_key_create(&(fKey), key_delete);
215 ~TThreadTLSArrayWrapper() {
216 pthread_key_delete(fKey);
220 void *ptr = pthread_getspecific(fKey);
222 ptr =
new type[size];
224 (
void) pthread_setspecific(fKey, ptr);
241 # define TTHREAD_TLS(type) static TThreadTLSWrapper<type>
242 # define TTHREAD_TLS_ARRAY(type,size,name) static TThreadTLSArrayWrapper<type,size> name;
243 # define TTHREAD_TLS_PTR(name) &(name.get())
244 # define TTHREAD_TLS_OBJ(index,type,name) type &name( TTHREAD_TLS_INIT<index,type>() )
248 #error "No Thread Local Storage (TLS) technology for this platform specified."
258 #define TTHREAD_TLS_DECL_IMPL(type, name, ptr, arg) \
259 TTHREAD_TLS(type *) ptr = 0; \
260 if (!ptr) ptr = new type(arg); \
263 #define TTHREAD_TLS_DECL_IMPL2(type, name, ptr, arg1, arg2) \
264 TTHREAD_TLS(type *) ptr = 0; \
265 if (!ptr) ptr = new type(arg1,arg2); \
268 #ifndef TTHREAD_TLS_DECL
270 #define TTHREAD_TLS_DECL(type, name) \
271 TTHREAD_TLS_DECL_IMPL(type,name,_R__JOIN_(ptr,__LINE__),)
273 #define TTHREAD_TLS_DECL_ARG(type, name, arg) \
274 TTHREAD_TLS_DECL_IMPL(type,name,_R__JOIN_(ptr,__LINE__),arg)
276 #define TTHREAD_TLS_DECL_ARG2(type, name, arg1, arg2) \
277 TTHREAD_TLS_DECL_IMPL2(type,name,_R__JOIN_(ptr,__LINE__),arg1,arg2)
281 template <
int marker,
typename T>
282 T &TTHREAD_TLS_INIT() {
283 TTHREAD_TLS(
T*) ptr =
NULL;
292 template <
int marker,
typename Array,
typename T>
293 Array &TTHREAD_TLS_INIT_ARRAY() {
303 template <
int marker,
typename T,
typename ArgType>
304 T &TTHREAD_TLS_INIT(ArgType arg) {
305 TTHREAD_TLS(
T*) ptr =
NULL;
316 #if defined(R__HAS_THREAD_LOCAL)
318 # define TTHREAD_TLS_DECLARE(type,name)
319 # define TTHREAD_TLS_INIT(type,name,value) thread_local type name = (value)
320 # define TTHREAD_TLS_SET(type,name,value) name = (value)
321 # define TTHREAD_TLS_GET(type,name) (name)
322 # define TTHREAD_TLS_FREE(name)
324 #elif defined(R__HAS___THREAD)
326 # define TTHREAD_TLS_DECLARE(type,name)
327 # define TTHREAD_TLS_INIT(type,name,value) static __thread type name = (value)
328 # define TTHREAD_TLS_SET(type,name,value) name = (value)
329 # define TTHREAD_TLS_GET(type,name) (name)
330 # define TTHREAD_TLS_FREE(name)
332 #elif defined(R__HAS_DECLSPEC_THREAD)
334 # define TTHREAD_TLS_DECLARE(type,name)
335 # define TTHREAD_TLS_INIT(type,name,value) static __declspec(thread) type name = (value)
336 # define TTHREAD_TLS_SET(type,name,value) name = (value)
337 # define TTHREAD_TLS_GET(type,name) (name)
338 # define TTHREAD_TLS_FREE(name)
340 #elif defined(R__HAS_PTHREAD)
345 # define TTHREAD_TLS_DECLARE(type,name) \
346 static pthread_key_t _##name##_key; \
347 static void _##name##_key_delete(void * arg) \
349 assert (NULL != arg); \
352 static void _##name##_key_create(void) \
355 _ret = pthread_key_create(&(_##name##_key), _##name##_key_delete); \
357 assert (0 == _ret); \
359 static pthread_once_t _##name##_once = PTHREAD_ONCE_INIT;
361 # define TTHREAD_TLS_INIT(type,name,value) \
364 (void) pthread_once(&(_##name##_once), _##name##_key_create); \
365 if ((_ptr = pthread_getspecific(_##name##_key)) == NULL) { \
366 _ptr = malloc(sizeof(type)); \
367 assert (NULL != _ptr); \
368 (void) pthread_setspecific(_##name##_key, _ptr); \
369 *((type*)_ptr) = (value); \
373 # define TTHREAD_TLS_SET(type,name,value) \
375 void *_ptr = pthread_getspecific(_##name##_key); \
376 assert (NULL != _ptr); \
377 *((type*)_ptr) = (value); \
380 # define TTHREAD_TLS_GET(type,name) \
381 *((type*)pthread_getspecific(_##name##_key))
383 # define TTHREAD_TLS_FREE(name) \
384 pthread_key_delete(_##name##_key);
388 #error "No Thread Local Storage (TLS) technology for this platform specified."
392 #endif // __cplusplus
if(pyself &&pyself!=Py_None)
Binding & operator=(OUT(*fun)(void))
typedef void((*Func_t)())