mirror of
https://github.com/jemalloc/jemalloc.git
synced 2026-07-24 05:33:06 +00:00
Extract initialization logic from jemalloc.c into jemalloc_init module
This commit is contained in:
42
include/jemalloc/internal/jemalloc_init.h
Normal file
42
include/jemalloc/internal/jemalloc_init.h
Normal file
@@ -0,0 +1,42 @@
|
||||
#ifndef JEMALLOC_INTERNAL_JEMALLOC_INIT_H
|
||||
#define JEMALLOC_INTERNAL_JEMALLOC_INIT_H
|
||||
|
||||
enum malloc_init_e {
|
||||
malloc_init_uninitialized = 3,
|
||||
malloc_init_a0_initialized = 2,
|
||||
malloc_init_recursible = 1,
|
||||
malloc_init_initialized = 0 /* Common case --> jnz. */
|
||||
};
|
||||
typedef enum malloc_init_e malloc_init_t;
|
||||
|
||||
extern malloc_init_t malloc_init_state;
|
||||
|
||||
bool malloc_is_initializer(void);
|
||||
bool malloc_initializer_is_set(void);
|
||||
void malloc_initializer_set(void);
|
||||
|
||||
bool malloc_init_hard_a0(void);
|
||||
bool malloc_init_hard(void);
|
||||
|
||||
JEMALLOC_ALWAYS_INLINE bool
|
||||
malloc_init_a0(void) {
|
||||
if (unlikely(malloc_init_state == malloc_init_uninitialized)) {
|
||||
return malloc_init_hard_a0();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
JEMALLOC_ALWAYS_INLINE bool
|
||||
malloc_initialized(void) {
|
||||
return (malloc_init_state == malloc_init_initialized);
|
||||
}
|
||||
|
||||
JEMALLOC_ALWAYS_INLINE bool
|
||||
malloc_init(void) {
|
||||
if (unlikely(!malloc_initialized()) && malloc_init_hard()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif /* JEMALLOC_INTERNAL_JEMALLOC_INIT_H */
|
||||
Reference in New Issue
Block a user