112 static void register_tls(
void (* init)(),
void (* fini)());
153 MAX_BYTES_NEEDED =
sizeof(
T) +
sizeof(
long) - 1,
154 ARRAY_SIZE = MAX_BYTES_NEEDED /
sizeof(long)
158 long _reserved_space[ARRAY_SIZE];
178 } u = {_reserved_space};
234 #define TLS_STRUCT(Type, Name, InitFn) \ 236 typedef tls_tricks::tls_blob< Type > Wrapper; \ 237 Type &operator*() { return *get(); } \ 238 Type* operator->() { return get(); } \ 239 operator Type*() { return get(); } \ 240 static Wrapper* get_wrapper() { \ 241 static __thread Wrapper val; \ 244 static Type* get() { return get_wrapper()->get(); } \ 245 static void init() { get_wrapper()->init(); } \ 246 static void fini() { get_wrapper()->fini(); } \ 248 static bool initialized = false; \ 251 tls_tricks::tls_manager::register_tls(&init, &fini); \ 252 initialized = true; \ 271 #define DECLARE_TLS(Type, Name) \ 273 TLS_STRUCT(Type, Name##_tls_wrapper, Name##_tls_wrapper) Name 292 #define DECLARE_TLS_SCHWARZ(Name) \ 293 static struct Name##_tls_wrapper_schwarz { \ 294 Name##_tls_wrapper_schwarz(); \ 305 #define DEFINE_TLS_SCHWARZ(Type, Name) \ 306 static TLS_STRUCT(Type, Name##_tls_wrapper, static void init_wrapper) Name; \ 307 Name##_tls_wrapper_schwarz::Name##_tls_wrapper_schwarz() { \ 308 Name##_tls_wrapper::init_wrapper(); \ Wrapper for a type, used by TLS_STRUCT helper macro.
Definition: tls.h:151
static __thread bool _thread_initialized
Definition: tls.h:118
static void register_tls(void(*init)(), void(*fini)())
Definition: tls.cpp:93
static struct tls_manager_schwarz tlsm_schwarz_one_and_only
Definition: tls.h:142
static void thread_init()
Definition: tls.cpp:107
void init()
Definition: tls.h:163
~tls_manager_schwarz()
Destructor: invokes global init of all registered tls destructors.
Definition: tls.h:137
void fini()
Definition: tls.h:169
A management class for non-POD thread-local storage.
Definition: tls.h:106
static void thread_fini()
Definition: tls.cpp:118
static void global_fini()
Definition: tls.cpp:85
Static struct to make sure tls_manager's global init() and fini() are called.
Definition: tls.h:130
static void global_init()
Definition: tls.cpp:77
A namespace for thread-local storage tricks.
Definition: tls.h:83
#define T
Definition: w_okvl_inl.h:45
tls_manager_schwarz()
Constructor: invokes global init of all registered tls initializers.
Definition: tls.h:132