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