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