2017-04-27 09:37:44 +08:00
|
|
|
#ifdef JEMALLOC_INTERNAL_TSD_MALLOC_THREAD_CLEANUP_H
|
|
|
|
#error This file should be included only once, by tsd.h.
|
|
|
|
#endif
|
|
|
|
#define JEMALLOC_INTERNAL_TSD_MALLOC_THREAD_CLEANUP_H
|
|
|
|
|
2023-06-10 08:37:47 +08:00
|
|
|
#include "jemalloc/internal/jemalloc_preamble.h"
|
2023-06-13 07:05:18 +08:00
|
|
|
#include "jemalloc/internal/tsd_internals.h"
|
2023-06-10 08:37:47 +08:00
|
|
|
#include "jemalloc/internal/tsd_types.h"
|
2023-06-13 07:05:18 +08:00
|
|
|
|
2019-04-16 06:36:31 +08:00
|
|
|
#define JEMALLOC_TSD_TYPE_ATTR(type) __thread type JEMALLOC_TLS_MODEL
|
|
|
|
|
|
|
|
extern JEMALLOC_TSD_TYPE_ATTR(tsd_t) tsd_tls;
|
|
|
|
extern JEMALLOC_TSD_TYPE_ATTR(bool) tsd_initialized;
|
2017-04-27 09:37:44 +08:00
|
|
|
extern bool tsd_booted;
|
|
|
|
|
|
|
|
/* Initialization/cleanup. */
|
|
|
|
JEMALLOC_ALWAYS_INLINE bool
|
|
|
|
tsd_cleanup_wrapper(void) {
|
|
|
|
if (tsd_initialized) {
|
|
|
|
tsd_initialized = false;
|
|
|
|
tsd_cleanup(&tsd_tls);
|
|
|
|
}
|
|
|
|
return tsd_initialized;
|
|
|
|
}
|
|
|
|
|
|
|
|
JEMALLOC_ALWAYS_INLINE bool
|
|
|
|
tsd_boot0(void) {
|
2022-01-23 02:14:16 +08:00
|
|
|
_malloc_tsd_cleanup_register(&tsd_cleanup_wrapper);
|
2017-04-27 09:37:44 +08:00
|
|
|
tsd_booted = true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
JEMALLOC_ALWAYS_INLINE void
|
|
|
|
tsd_boot1(void) {
|
|
|
|
/* Do nothing. */
|
|
|
|
}
|
|
|
|
|
|
|
|
JEMALLOC_ALWAYS_INLINE bool
|
|
|
|
tsd_boot(void) {
|
|
|
|
return tsd_boot0();
|
|
|
|
}
|
|
|
|
|
|
|
|
JEMALLOC_ALWAYS_INLINE bool
|
|
|
|
tsd_booted_get(void) {
|
|
|
|
return tsd_booted;
|
|
|
|
}
|
|
|
|
|
|
|
|
JEMALLOC_ALWAYS_INLINE bool
|
|
|
|
tsd_get_allocates(void) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get/set. */
|
|
|
|
JEMALLOC_ALWAYS_INLINE tsd_t *
|
|
|
|
tsd_get(bool init) {
|
|
|
|
return &tsd_tls;
|
|
|
|
}
|
|
|
|
JEMALLOC_ALWAYS_INLINE void
|
|
|
|
tsd_set(tsd_t *val) {
|
|
|
|
assert(tsd_booted);
|
|
|
|
if (likely(&tsd_tls != val)) {
|
|
|
|
tsd_tls = (*val);
|
|
|
|
}
|
|
|
|
tsd_initialized = true;
|
|
|
|
}
|