1 #ifdef JEMALLOC_INTERNAL_TSD_MALLOC_THREAD_CLEANUP_H 2 #error This file should be included only once, by tsd.h. 3 #endif 4 #define JEMALLOC_INTERNAL_TSD_MALLOC_THREAD_CLEANUP_H 5 6 extern __thread tsd_t tsd_tls; 7 extern __thread bool tsd_initialized; 8 extern bool tsd_booted; 9 10 /* Initialization/cleanup. */ 11 JEMALLOC_ALWAYS_INLINE bool tsd_cleanup_wrapper(void)12tsd_cleanup_wrapper(void) { 13 if (tsd_initialized) { 14 tsd_initialized = false; 15 tsd_cleanup(&tsd_tls); 16 } 17 return tsd_initialized; 18 } 19 20 JEMALLOC_ALWAYS_INLINE bool tsd_boot0(void)21tsd_boot0(void) { 22 malloc_tsd_cleanup_register(&tsd_cleanup_wrapper); 23 tsd_booted = true; 24 return false; 25 } 26 27 JEMALLOC_ALWAYS_INLINE void tsd_boot1(void)28tsd_boot1(void) { 29 /* Do nothing. */ 30 } 31 32 JEMALLOC_ALWAYS_INLINE bool tsd_boot(void)33tsd_boot(void) { 34 return tsd_boot0(); 35 } 36 37 JEMALLOC_ALWAYS_INLINE bool tsd_booted_get(void)38tsd_booted_get(void) { 39 return tsd_booted; 40 } 41 42 JEMALLOC_ALWAYS_INLINE bool tsd_get_allocates(void)43tsd_get_allocates(void) { 44 return false; 45 } 46 47 /* Get/set. */ 48 JEMALLOC_ALWAYS_INLINE tsd_t * tsd_get(bool init)49tsd_get(bool init) { 50 assert(tsd_booted); 51 return &tsd_tls; 52 } 53 JEMALLOC_ALWAYS_INLINE void tsd_set(tsd_t * val)54tsd_set(tsd_t *val) { 55 assert(tsd_booted); 56 if (likely(&tsd_tls != val)) { 57 tsd_tls = (*val); 58 } 59 tsd_initialized = true; 60 } 61