• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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(UNUSED bool init)42 tsd_get(UNUSED bool init) {
43 	assert(tsd_booted);
44 	return &tsd_tls;
45 }
46 
47 JEMALLOC_ALWAYS_INLINE void
tsd_set(tsd_t * val)48 tsd_set(tsd_t *val) {
49 	assert(tsd_booted);
50 	if (likely(&tsd_tls != val)) {
51 		tsd_tls = (*val);
52 	}
53 	if (pthread_setspecific(tsd_tsd, (void *)(&tsd_tls)) != 0) {
54 		malloc_write("<jemalloc>: Error setting tsd.\n");
55 		if (opt_abort) {
56 			abort();
57 		}
58 	}
59 }
60