]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/jemalloc/include/jemalloc/internal/tsd_malloc_thread_cleanup.h
MFV r345988:
[FreeBSD/FreeBSD.git] / contrib / jemalloc / include / jemalloc / internal / tsd_malloc_thread_cleanup.h
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
12 tsd_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
21 tsd_boot0(void) {
22         malloc_tsd_cleanup_register(&tsd_cleanup_wrapper);
23         tsd_booted = true;
24         return false;
25 }
26
27 JEMALLOC_ALWAYS_INLINE void
28 tsd_boot1(void) {
29         /* Do nothing. */
30 }
31
32 JEMALLOC_ALWAYS_INLINE bool
33 tsd_boot(void) {
34         return tsd_boot0();
35 }
36
37 JEMALLOC_ALWAYS_INLINE bool
38 tsd_booted_get(void) {
39         return tsd_booted;
40 }
41
42 JEMALLOC_ALWAYS_INLINE bool
43 tsd_get_allocates(void) {
44         return false;
45 }
46
47 /* Get/set. */
48 JEMALLOC_ALWAYS_INLINE tsd_t *
49 tsd_get(bool init) {
50         assert(tsd_booted);
51         return &tsd_tls;
52 }
53 JEMALLOC_ALWAYS_INLINE void
54 tsd_set(tsd_t *val) {
55         assert(tsd_booted);
56         if (likely(&tsd_tls != val)) {
57                 tsd_tls = (*val);
58         }
59         tsd_initialized = true;
60 }