this repo has no description
at fixPythonPipStalling 52 lines 1.3 kB view raw
1#ifndef _XTRACE_TLS_H_ 2#define _XTRACE_TLS_H_ 3 4#include <stddef.h> 5#include <stdbool.h> 6#include <mach/port.h> 7#include "base.h" 8 9XTRACE_DECLARATIONS_C_BEGIN 10 11typedef void (*xtrace_tls_destructor_f)(void* value); 12 13#define DEFINE_XTRACE_TLS_VAR(type, name, default_value, destructor) \ 14 static char name ## _key = '\0'; \ 15 XTRACE_INLINE \ 16 void destroy_ ## name(void* value) { \ 17 void (*dtor)(type*) = (destructor); \ 18 if (dtor) { \ 19 dtor((type*)value); \ 20 } \ 21 }; \ 22 XTRACE_INLINE \ 23 type get_ ## name(void) { \ 24 bool created = false; \ 25 type* var = (type*)xtrace_tls(&(name ## _key), sizeof(type), &created, destroy_ ## name); \ 26 if (created) { \ 27 *var = default_value; \ 28 } \ 29 return *var; \ 30 }; \ 31 XTRACE_INLINE \ 32 void set_ ## name(type value) { \ 33 bool created = false; \ 34 type* var = (type*)xtrace_tls(&(name ## _key), sizeof(type), NULL, destroy_ ## name); \ 35 *var = value; \ 36 }; \ 37 XTRACE_INLINE \ 38 type* get_ptr_ ## name(void) { \ 39 bool created = false; \ 40 type* var = (type*)xtrace_tls(&(name ## _key), sizeof(type), &created, destroy_ ## name); \ 41 if (created) { \ 42 *var = default_value; \ 43 } \ 44 return var; \ 45 }; 46 47void* xtrace_tls(void* key, size_t size, bool* created, xtrace_tls_destructor_f destructor); 48void xtrace_tls_thread_cleanup(void); 49 50XTRACE_DECLARATIONS_C_END 51 52#endif // _XTRACE_TLS_H_