reuse is_init when possible
This commit is contained in:
parent
7733047c7b
commit
1a7b8079d0
24
malloc.c
24
malloc.c
@ -564,12 +564,22 @@ static void post_fork_child(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline bool is_init(void) {
|
||||||
|
return atomic_load_explicit(&ro.initialized, memory_order_acquire);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void enforce_init(void) {
|
||||||
|
if (!is_init()) {
|
||||||
|
fatal_error("invalid uninitialized allocator usage");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
COLD static void init_slow_path(void) {
|
COLD static void init_slow_path(void) {
|
||||||
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
|
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
pthread_mutex_lock(&mutex);
|
pthread_mutex_lock(&mutex);
|
||||||
|
|
||||||
if (atomic_load_explicit(&ro.initialized, memory_order_acquire)) {
|
if (is_init()) {
|
||||||
pthread_mutex_unlock(&mutex);
|
pthread_mutex_unlock(&mutex);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -644,7 +654,7 @@ COLD static void init_slow_path(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static inline void init(void) {
|
static inline void init(void) {
|
||||||
if (likely(atomic_load_explicit(&ro.initialized, memory_order_acquire))) {
|
if (likely(is_init())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -657,16 +667,6 @@ COLD __attribute__((constructor(101))) static void trigger_early_init(void) {
|
|||||||
h_free(h_malloc(16));
|
h_free(h_malloc(16));
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void enforce_init(void) {
|
|
||||||
if (!atomic_load_explicit(&ro.initialized, memory_order_acquire)) {
|
|
||||||
fatal_error("invalid uninitialized allocator usage");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline bool is_init(void) {
|
|
||||||
return atomic_load_explicit(&ro.initialized, memory_order_acquire);
|
|
||||||
}
|
|
||||||
|
|
||||||
static size_t get_guard_size(struct random_state *state, size_t size) {
|
static size_t get_guard_size(struct random_state *state, size_t size) {
|
||||||
return (get_random_u64_uniform(state, size / PAGE_SIZE / 8) + 1) * PAGE_SIZE;
|
return (get_random_u64_uniform(state, size / PAGE_SIZE / 8) + 1) * PAGE_SIZE;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user