mirror of
https://github.com/jemalloc/jemalloc.git
synced 2026-08-10 09:41:04 +03:00
Reformat the codebase with the clang-format 18.
This commit is contained in:
parent
a952a3b8b0
commit
6200e8987f
346 changed files with 18286 additions and 17770 deletions
123
src/tsd.c
123
src/tsd.c
|
|
@ -20,19 +20,20 @@ bool tsd_booted = false;
|
|||
#elif (defined(JEMALLOC_TLS))
|
||||
JEMALLOC_TSD_TYPE_ATTR(tsd_t) tsd_tls = TSD_INITIALIZER;
|
||||
pthread_key_t tsd_tsd;
|
||||
bool tsd_booted = false;
|
||||
bool tsd_booted = false;
|
||||
#elif (defined(_WIN32))
|
||||
#if defined(JEMALLOC_LEGACY_WINDOWS_SUPPORT) || !defined(_MSC_VER)
|
||||
DWORD tsd_tsd;
|
||||
# if defined(JEMALLOC_LEGACY_WINDOWS_SUPPORT) || !defined(_MSC_VER)
|
||||
DWORD tsd_tsd;
|
||||
tsd_wrapper_t tsd_boot_wrapper = {TSD_INITIALIZER, false};
|
||||
#else
|
||||
JEMALLOC_TSD_TYPE_ATTR(tsd_wrapper_t) tsd_wrapper_tls = { TSD_INITIALIZER, false };
|
||||
#endif
|
||||
# else
|
||||
JEMALLOC_TSD_TYPE_ATTR(tsd_wrapper_t)
|
||||
tsd_wrapper_tls = {TSD_INITIALIZER, false};
|
||||
# endif
|
||||
bool tsd_booted = false;
|
||||
#if JEMALLOC_WIN32_TLSGETVALUE2
|
||||
TGV2 tls_get_value2 = NULL;
|
||||
# if JEMALLOC_WIN32_TLSGETVALUE2
|
||||
TGV2 tls_get_value2 = NULL;
|
||||
HMODULE tgv2_mod = NULL;
|
||||
#endif
|
||||
# endif
|
||||
#else
|
||||
|
||||
/*
|
||||
|
|
@ -45,17 +46,12 @@ struct tsd_init_head_s {
|
|||
malloc_mutex_t lock;
|
||||
};
|
||||
|
||||
pthread_key_t tsd_tsd;
|
||||
tsd_init_head_t tsd_init_head = {
|
||||
ql_head_initializer(blocks),
|
||||
MALLOC_MUTEX_INITIALIZER
|
||||
};
|
||||
pthread_key_t tsd_tsd;
|
||||
tsd_init_head_t tsd_init_head = {
|
||||
ql_head_initializer(blocks), MALLOC_MUTEX_INITIALIZER};
|
||||
|
||||
tsd_wrapper_t tsd_boot_wrapper = {
|
||||
false,
|
||||
TSD_INITIALIZER
|
||||
};
|
||||
bool tsd_booted = false;
|
||||
tsd_wrapper_t tsd_boot_wrapper = {false, TSD_INITIALIZER};
|
||||
bool tsd_booted = false;
|
||||
#endif
|
||||
|
||||
JEMALLOC_DIAGNOSTIC_POP
|
||||
|
|
@ -64,7 +60,7 @@ JEMALLOC_DIAGNOSTIC_POP
|
|||
|
||||
/* A list of all the tsds in the nominal state. */
|
||||
typedef ql_head(tsd_t) tsd_list_t;
|
||||
static tsd_list_t tsd_nominal_tsds = ql_head_initializer(tsd_nominal_tsds);
|
||||
static tsd_list_t tsd_nominal_tsds = ql_head_initializer(tsd_nominal_tsds);
|
||||
static malloc_mutex_t tsd_nominal_tsds_lock;
|
||||
|
||||
/* How many slow-path-enabling features are turned on. */
|
||||
|
|
@ -73,13 +69,13 @@ static atomic_u32_t tsd_global_slow_count = ATOMIC_INIT(0);
|
|||
static bool
|
||||
tsd_in_nominal_list(tsd_t *tsd) {
|
||||
tsd_t *tsd_list;
|
||||
bool found = false;
|
||||
bool found = false;
|
||||
/*
|
||||
* We don't know that tsd is nominal; it might not be safe to get data
|
||||
* out of it here.
|
||||
*/
|
||||
malloc_mutex_lock(TSDN_NULL, &tsd_nominal_tsds_lock);
|
||||
ql_foreach(tsd_list, &tsd_nominal_tsds, TSD_MANGLE(tsd_link)) {
|
||||
ql_foreach (tsd_list, &tsd_nominal_tsds, TSD_MANGLE(tsd_link)) {
|
||||
if (tsd == tsd_list) {
|
||||
found = true;
|
||||
break;
|
||||
|
|
@ -117,7 +113,7 @@ tsd_force_recompute(tsdn_t *tsdn) {
|
|||
atomic_fence(ATOMIC_RELEASE);
|
||||
malloc_mutex_lock(tsdn, &tsd_nominal_tsds_lock);
|
||||
tsd_t *remote_tsd;
|
||||
ql_foreach(remote_tsd, &tsd_nominal_tsds, TSD_MANGLE(tsd_link)) {
|
||||
ql_foreach (remote_tsd, &tsd_nominal_tsds, TSD_MANGLE(tsd_link)) {
|
||||
assert(tsd_atomic_load(&remote_tsd->state, ATOMIC_RELAXED)
|
||||
<= tsd_state_nominal_max);
|
||||
tsd_atomic_store(&remote_tsd->state,
|
||||
|
|
@ -143,7 +139,8 @@ tsd_global_slow_inc(tsdn_t *tsdn) {
|
|||
tsd_force_recompute(tsdn);
|
||||
}
|
||||
|
||||
void tsd_global_slow_dec(tsdn_t *tsdn) {
|
||||
void
|
||||
tsd_global_slow_dec(tsdn_t *tsdn) {
|
||||
atomic_fetch_sub_u32(&tsd_global_slow_count, 1, ATOMIC_RELAXED);
|
||||
/* See the note in ..._inc(). */
|
||||
tsd_force_recompute(tsdn);
|
||||
|
|
@ -180,8 +177,8 @@ tsd_slow_update(tsd_t *tsd) {
|
|||
uint8_t old_state;
|
||||
do {
|
||||
uint8_t new_state = tsd_state_compute(tsd);
|
||||
old_state = tsd_atomic_exchange(&tsd->state, new_state,
|
||||
ATOMIC_ACQUIRE);
|
||||
old_state = tsd_atomic_exchange(
|
||||
&tsd->state, new_state, ATOMIC_ACQUIRE);
|
||||
} while (old_state == tsd_state_nominal_recompute);
|
||||
|
||||
te_recompute_fast_threshold(tsd);
|
||||
|
|
@ -211,8 +208,8 @@ tsd_state_set(tsd_t *tsd, uint8_t new_state) {
|
|||
assert(tsd_in_nominal_list(tsd));
|
||||
if (new_state > tsd_state_nominal_max) {
|
||||
tsd_remove_nominal(tsd);
|
||||
tsd_atomic_store(&tsd->state, new_state,
|
||||
ATOMIC_RELAXED);
|
||||
tsd_atomic_store(
|
||||
&tsd->state, new_state, ATOMIC_RELAXED);
|
||||
} else {
|
||||
/*
|
||||
* This is the tricky case. We're transitioning from
|
||||
|
|
@ -235,8 +232,7 @@ tsd_prng_state_init(tsd_t *tsd) {
|
|||
* cost of test repeatability. For debug builds, instead use a
|
||||
* deterministic seed.
|
||||
*/
|
||||
*tsd_prng_statep_get(tsd) = config_debug ? 0 :
|
||||
(uint64_t)(uintptr_t)tsd;
|
||||
*tsd_prng_statep_get(tsd) = config_debug ? 0 : (uint64_t)(uintptr_t)tsd;
|
||||
}
|
||||
|
||||
static bool
|
||||
|
|
@ -264,8 +260,8 @@ assert_tsd_data_cleanup_done(tsd_t *tsd) {
|
|||
|
||||
static bool
|
||||
tsd_data_init_nocleanup(tsd_t *tsd) {
|
||||
assert(tsd_state_get(tsd) == tsd_state_reincarnated ||
|
||||
tsd_state_get(tsd) == tsd_state_minimal_initialized);
|
||||
assert(tsd_state_get(tsd) == tsd_state_reincarnated
|
||||
|| tsd_state_get(tsd) == tsd_state_minimal_initialized);
|
||||
/*
|
||||
* During reincarnation, there is no guarantee that the cleanup function
|
||||
* will be called (deallocation may happen after all tsd destructors).
|
||||
|
|
@ -358,15 +354,15 @@ malloc_tsd_dalloc(void *wrapper) {
|
|||
}
|
||||
|
||||
#if defined(JEMALLOC_MALLOC_THREAD_CLEANUP) || defined(_WIN32)
|
||||
static unsigned ncleanups;
|
||||
static unsigned ncleanups;
|
||||
static malloc_tsd_cleanup_t cleanups[MALLOC_TSD_CLEANUPS_MAX];
|
||||
|
||||
#ifndef _WIN32
|
||||
# ifndef _WIN32
|
||||
JEMALLOC_EXPORT
|
||||
#endif
|
||||
# endif
|
||||
void
|
||||
_malloc_thread_cleanup(void) {
|
||||
bool pending[MALLOC_TSD_CLEANUPS_MAX], again;
|
||||
bool pending[MALLOC_TSD_CLEANUPS_MAX], again;
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < ncleanups; i++) {
|
||||
|
|
@ -386,9 +382,9 @@ _malloc_thread_cleanup(void) {
|
|||
} while (again);
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
# ifndef _WIN32
|
||||
JEMALLOC_EXPORT
|
||||
#endif
|
||||
# endif
|
||||
void
|
||||
_malloc_tsd_cleanup_register(bool (*f)(void)) {
|
||||
assert(ncleanups < MALLOC_TSD_CLEANUPS_MAX);
|
||||
|
|
@ -446,7 +442,7 @@ tsd_cleanup(void *arg) {
|
|||
}
|
||||
#ifdef JEMALLOC_JET
|
||||
test_callback_t test_callback = *tsd_test_callbackp_get_unsafe(tsd);
|
||||
int *data = tsd_test_datap_get_unsafe(tsd);
|
||||
int *data = tsd_test_datap_get_unsafe(tsd);
|
||||
if (test_callback != NULL) {
|
||||
test_callback(data);
|
||||
}
|
||||
|
|
@ -461,7 +457,7 @@ malloc_tsd_boot0(void) {
|
|||
ncleanups = 0;
|
||||
#endif
|
||||
if (malloc_mutex_init(&tsd_nominal_tsds_lock, "tsd_nominal_tsds_lock",
|
||||
WITNESS_RANK_OMIT, malloc_mutex_rank_exclusive)) {
|
||||
WITNESS_RANK_OMIT, malloc_mutex_rank_exclusive)) {
|
||||
return NULL;
|
||||
}
|
||||
if (tsd_boot0()) {
|
||||
|
|
@ -483,11 +479,11 @@ malloc_tsd_boot1(void) {
|
|||
static BOOL WINAPI
|
||||
_tls_callback(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
|
||||
switch (fdwReason) {
|
||||
#ifdef JEMALLOC_LAZY_LOCK
|
||||
# ifdef JEMALLOC_LAZY_LOCK
|
||||
case DLL_THREAD_ATTACH:
|
||||
isthreaded = true;
|
||||
break;
|
||||
#endif
|
||||
# endif
|
||||
case DLL_THREAD_DETACH:
|
||||
_malloc_thread_cleanup();
|
||||
break;
|
||||
|
|
@ -502,35 +498,36 @@ _tls_callback(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
|
|||
* hooked "read". We won't read for the rest of the file, so we can get away
|
||||
* with unhooking.
|
||||
*/
|
||||
#ifdef read
|
||||
# undef read
|
||||
# ifdef read
|
||||
# undef read
|
||||
# endif
|
||||
|
||||
# ifdef _MSC_VER
|
||||
# ifdef _M_IX86
|
||||
# pragma comment(linker, "/INCLUDE:__tls_used")
|
||||
# pragma comment(linker, "/INCLUDE:_tls_callback")
|
||||
# else
|
||||
# pragma comment(linker, "/INCLUDE:_tls_used")
|
||||
# pragma comment( \
|
||||
linker, "/INCLUDE:" STRINGIFY(tls_callback))
|
||||
# endif
|
||||
# pragma section(".CRT$XLY", long, read)
|
||||
# endif
|
||||
JEMALLOC_SECTION(".CRT$XLY")
|
||||
JEMALLOC_ATTR(used) BOOL(WINAPI *const tls_callback)(
|
||||
HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) = _tls_callback;
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# ifdef _M_IX86
|
||||
# pragma comment(linker, "/INCLUDE:__tls_used")
|
||||
# pragma comment(linker, "/INCLUDE:_tls_callback")
|
||||
# else
|
||||
# pragma comment(linker, "/INCLUDE:_tls_used")
|
||||
# pragma comment(linker, "/INCLUDE:" STRINGIFY(tls_callback) )
|
||||
# endif
|
||||
# pragma section(".CRT$XLY",long,read)
|
||||
#endif
|
||||
JEMALLOC_SECTION(".CRT$XLY") JEMALLOC_ATTR(used)
|
||||
BOOL (WINAPI *const tls_callback)(HINSTANCE hinstDLL,
|
||||
DWORD fdwReason, LPVOID lpvReserved) = _tls_callback;
|
||||
#endif
|
||||
|
||||
#if (!defined(JEMALLOC_MALLOC_THREAD_CLEANUP) && !defined(JEMALLOC_TLS) && \
|
||||
!defined(_WIN32))
|
||||
#if (!defined(JEMALLOC_MALLOC_THREAD_CLEANUP) && !defined(JEMALLOC_TLS) \
|
||||
&& !defined(_WIN32))
|
||||
void *
|
||||
tsd_init_check_recursion(tsd_init_head_t *head, tsd_init_block_t *block) {
|
||||
pthread_t self = pthread_self();
|
||||
pthread_t self = pthread_self();
|
||||
tsd_init_block_t *iter;
|
||||
|
||||
/* Check whether this thread has already inserted into the list. */
|
||||
malloc_mutex_lock(TSDN_NULL, &head->lock);
|
||||
ql_foreach(iter, &head->blocks, link) {
|
||||
ql_foreach (iter, &head->blocks, link) {
|
||||
if (iter->thread == self) {
|
||||
malloc_mutex_unlock(TSDN_NULL, &head->lock);
|
||||
return iter->data;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue