mirror of
https://github.com/jemalloc/jemalloc.git
synced 2026-07-23 05:03:10 +00:00
This is a prerequisite to achieving self-contained headers. Previously, the various tsd implementation headers (`tsd_generic.h`, `tsd_tls.h`, `tsd_malloc_thread_cleanup.h`, and `tsd_win.h`) relied implicitly on being included in `tsd.h` after a variety of dependencies had been defined above them. This commit instead makes these dependencies explicit by splitting them out into a separate file, `tsd_internals.h`, which each of the tsd implementation headers includes directly.
63 lines
1.2 KiB
C
63 lines
1.2 KiB
C
#ifdef JEMALLOC_INTERNAL_TSD_TLS_H
|
|
#error This file should be included only once, by tsd.h.
|
|
#endif
|
|
#define JEMALLOC_INTERNAL_TSD_TLS_H
|
|
|
|
#include "jemalloc/internal/tsd_internals.h"
|
|
|
|
#define JEMALLOC_TSD_TYPE_ATTR(type) __thread type JEMALLOC_TLS_MODEL
|
|
|
|
extern JEMALLOC_TSD_TYPE_ATTR(tsd_t) tsd_tls;
|
|
extern pthread_key_t tsd_tsd;
|
|
extern bool tsd_booted;
|
|
|
|
/* Initialization/cleanup. */
|
|
JEMALLOC_ALWAYS_INLINE bool
|
|
tsd_boot0(void) {
|
|
if (pthread_key_create(&tsd_tsd, &tsd_cleanup) != 0) {
|
|
return true;
|
|
}
|
|
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);
|
|
}
|
|
if (pthread_setspecific(tsd_tsd, (void *)(&tsd_tls)) != 0) {
|
|
malloc_write("<jemalloc>: Error setting tsd.\n");
|
|
if (opt_abort) {
|
|
abort();
|
|
}
|
|
}
|
|
}
|