mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-07-06 19:38:41 +03:00
Merge branch 'dev3' into dev3-bin
This commit is contained in:
commit
35e81c1a3d
5 changed files with 54 additions and 30 deletions
19
src/bitmap.c
19
src/bitmap.c
|
@ -184,26 +184,23 @@ static inline bool mi_bfield_atomic_try_clear_mask(_Atomic(mi_bfield_t)* b, mi_b
|
|||
return mi_bfield_atomic_try_clear_mask_of(b, mask, expect, all_clear);
|
||||
}
|
||||
|
||||
/*
|
||||
// Tries to clear a bit atomically. Returns `true` if the bit transitioned from 1 to 0
|
||||
// and `false` otherwise leaving the bfield `b` as-is.
|
||||
// `all_clear` is set to true if the new bfield became zero (and false otherwise)
|
||||
static inline bool mi_bfield_atomic_try_clear(_Atomic(mi_bfield_t)* b, size_t idx, bool* all_clear) {
|
||||
mi_decl_maybe_unused static inline bool mi_bfield_atomic_try_clear(_Atomic(mi_bfield_t)* b, size_t idx, bool* all_clear) {
|
||||
mi_assert_internal(idx < MI_BFIELD_BITS);
|
||||
const mi_bfield_t mask = mi_bfield_one()<<idx;
|
||||
return mi_bfield_atomic_try_clear_mask(b, mask, all_clear);
|
||||
}
|
||||
|
||||
|
||||
// Tries to clear a byte atomically, and returns true if the byte atomically transitioned from 0xFF to 0
|
||||
// `all_clear` is set to true if the new bfield became zero (and false otherwise)
|
||||
static inline bool mi_bfield_atomic_try_clear8(_Atomic(mi_bfield_t)*b, size_t idx, bool* all_clear) {
|
||||
mi_decl_maybe_unused static inline bool mi_bfield_atomic_try_clear8(_Atomic(mi_bfield_t)*b, size_t idx, bool* all_clear) {
|
||||
mi_assert_internal(idx < MI_BFIELD_BITS);
|
||||
mi_assert_internal((idx%8)==0);
|
||||
const mi_bfield_t mask = ((mi_bfield_t)0xFF)<<idx;
|
||||
return mi_bfield_atomic_try_clear_mask(b, mask, all_clear);
|
||||
}
|
||||
*/
|
||||
|
||||
// Try to clear a full field of bits atomically, and return true all bits transitioned from all 1's to 0's.
|
||||
// and false otherwise leaving the bit field as-is.
|
||||
|
@ -526,16 +523,16 @@ static inline bool mi_bchunk_try_clearN(mi_bchunk_t* chunk, size_t cidx, size_t
|
|||
// ------- mi_bchunk_try_find_and_clear ---------------------------------------
|
||||
|
||||
#if MI_OPT_SIMD && defined(__AVX2__)
|
||||
static inline __m256i mi_mm256_zero(void) {
|
||||
mi_decl_maybe_unused static inline __m256i mi_mm256_zero(void) {
|
||||
return _mm256_setzero_si256();
|
||||
}
|
||||
static inline __m256i mi_mm256_ones(void) {
|
||||
mi_decl_maybe_unused static inline __m256i mi_mm256_ones(void) {
|
||||
return _mm256_set1_epi64x(~0);
|
||||
}
|
||||
static inline bool mi_mm256_is_ones(__m256i vec) {
|
||||
mi_decl_maybe_unused static inline bool mi_mm256_is_ones(__m256i vec) {
|
||||
return _mm256_testc_si256(vec, _mm256_cmpeq_epi32(vec, vec));
|
||||
}
|
||||
static inline bool mi_mm256_is_zero( __m256i vec) {
|
||||
mi_decl_maybe_unused static inline bool mi_mm256_is_zero( __m256i vec) {
|
||||
return _mm256_testz_si256(vec,vec);
|
||||
}
|
||||
#endif
|
||||
|
@ -643,8 +640,7 @@ static inline bool mi_bchunk_try_find_and_clear_1(mi_bchunk_t* chunk, size_t n,
|
|||
return mi_bchunk_try_find_and_clear(chunk, pidx);
|
||||
}
|
||||
|
||||
#if !(MI_OPT_SIMD && defined(__AVX2__) && (MI_BCHUNK_BITS==512))
|
||||
static inline bool mi_bchunk_try_find_and_clear8_at(mi_bchunk_t* chunk, size_t chunk_idx, size_t* pidx) {
|
||||
mi_decl_maybe_unused static inline bool mi_bchunk_try_find_and_clear8_at(mi_bchunk_t* chunk, size_t chunk_idx, size_t* pidx) {
|
||||
const mi_bfield_t b = mi_atomic_load_relaxed(&chunk->bfields[chunk_idx]);
|
||||
// has_set8 has low bit in each byte set if the byte in x == 0xFF
|
||||
const mi_bfield_t has_set8 =
|
||||
|
@ -663,7 +659,6 @@ static inline bool mi_bchunk_try_find_and_clear8_at(mi_bchunk_t* chunk, size_t c
|
|||
}
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
// find least aligned byte in a chunk with all bits set, and try unset it atomically
|
||||
// set `*pidx` to its bit index (0 <= *pidx < MI_BCHUNK_BITS) on success.
|
||||
|
|
17
src/init.c
17
src/init.c
|
@ -246,8 +246,6 @@ static void mi_tld_main_init(void) {
|
|||
// Initialization of the (statically allocated) main heap, and the main tld and subproc.
|
||||
static void mi_heap_main_init(void) {
|
||||
if (heap_main.cookie == 0) {
|
||||
mi_subproc_main_init();
|
||||
mi_tld_main_init();
|
||||
// heap
|
||||
heap_main.cookie = 1;
|
||||
#if defined(__APPLE__) || defined(_WIN32) && !defined(MI_SHARED_LIB)
|
||||
|
@ -262,6 +260,9 @@ static void mi_heap_main_init(void) {
|
|||
heap_main.allow_page_reclaim = (mi_option_get(mi_option_page_reclaim_on_free) >= 0);
|
||||
heap_main.allow_page_abandon = (mi_option_get(mi_option_page_full_retain) >= 0);
|
||||
heap_main.page_full_retain = mi_option_get_clamp(mi_option_page_full_retain, -1, 32);
|
||||
|
||||
mi_subproc_main_init();
|
||||
mi_tld_main_init();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -666,14 +667,16 @@ void mi_process_init(void) mi_attr_noexcept {
|
|||
if (!mi_atomic_once(&process_init)) return;
|
||||
_mi_process_is_initialized = true;
|
||||
_mi_verbose_message("process init: 0x%zx\n", _mi_thread_id());
|
||||
mi_process_setup_auto_thread_done();
|
||||
|
||||
|
||||
mi_detect_cpu_features();
|
||||
mi_subproc_main_init();
|
||||
mi_tld_main_init();
|
||||
mi_heap_main_init();
|
||||
_mi_os_init();
|
||||
_mi_page_map_init();
|
||||
mi_heap_main_init();
|
||||
mi_tld_main_init();
|
||||
// the following two can potentially allocate (on freeBSD for locks and thread keys)
|
||||
mi_subproc_main_init();
|
||||
mi_process_setup_auto_thread_done();
|
||||
|
||||
#if MI_DEBUG
|
||||
_mi_verbose_message("debug level : %d\n", MI_DEBUG);
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue