28 #if !defined(HAVE_PTHREAD_H) && defined(WITH_THREADS)
29 # error WITH_THREADS defined, but pthreads not available
35 #ifdef TLS_STORAGE_CLASS
36 # define _fr_thread_local TLS_STORAGE_CLASS
43 # define fr_thread_local_setup(_t, _n) static _t _n;\
44 static inline int __fr_thread_local_destructor_##_n(pthread_destructor_t *ctx)\
46 pthread_destructor_t func = *ctx;\
50 static inline _t __fr_thread_local_init_##_n(pthread_destructor_t func)\
52 static pthread_destructor_t *ctx;\
54 ctx = talloc(talloc_autofree_context(), pthread_destructor_t);\
55 talloc_set_destructor(ctx, __fr_thread_local_destructor_##_n);\
60 # define fr_thread_local_init(_n, _f) __fr_thread_local_init_##_n(_f)
61 # define fr_thread_local_set(_n, _v) ((int)!((_n = _v) || 1))
62 # define fr_thread_local_get(_n) _n
63 # undef _fr_thread_local
64 # define _fr_thread_local
65 #elif defined(_fr_thread_local)
67 # define fr_thread_local_setup(_t, _n) static _fr_thread_local _t _n;\
68 static pthread_key_t __fr_thread_local_key_##_n;\
69 static pthread_once_t __fr_thread_local_once_##_n = PTHREAD_ONCE_INIT;\
70 static pthread_destructor_t __fr_thread_local_destructor_##_n = NULL;\
71 static inline void __fr_thread_local_key_init_##_n(void)\
73 (void) pthread_key_create(&__fr_thread_local_key_##_n, __fr_thread_local_destructor_##_n);\
75 static inline _t __fr_thread_local_init_##_n(pthread_destructor_t func)\
77 __fr_thread_local_destructor_##_n = func;\
78 (void) pthread_once(&__fr_thread_local_once_##_n, __fr_thread_local_key_init_##_n);\
81 # define fr_thread_local_init(_n, _f) __fr_thread_local_init_##_n(_f)
82 # define fr_thread_local_set(_n, _v) ((int)!((_n = _v) || 1))
83 # define fr_thread_local_get(_n) _n
void(* pthread_destructor_t)(void *)