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