mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-05-06 23:39:31 +03:00
Merge branch 'dev' into dev-slice
This commit is contained in:
commit
268dceaa12
3 changed files with 12 additions and 2 deletions
|
@ -275,6 +275,15 @@ static inline intptr_t mi_atomic_subi(_Atomic(intptr_t)*p, intptr_t sub) {
|
||||||
return (intptr_t)mi_atomic_addi(p, -sub);
|
return (intptr_t)mi_atomic_addi(p, -sub);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef _Atomic(uintptr_t) mi_atomic_once_t;
|
||||||
|
|
||||||
|
// Returns true only on the first invocation
|
||||||
|
static inline bool mi_atomic_once( mi_atomic_once_t* once ) {
|
||||||
|
if (mi_atomic_load_relaxed(once) != 0) return false; // quick test
|
||||||
|
uintptr_t expected = 0;
|
||||||
|
return mi_atomic_cas_strong_acq_rel(once, &expected, 1); // try to set to 1
|
||||||
|
}
|
||||||
|
|
||||||
// Yield
|
// Yield
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
|
@ -540,7 +540,8 @@ static void mi_detect_cpu_features(void) {
|
||||||
// Initialize the process; called by thread_init or the process loader
|
// Initialize the process; called by thread_init or the process loader
|
||||||
void mi_process_init(void) mi_attr_noexcept {
|
void mi_process_init(void) mi_attr_noexcept {
|
||||||
// ensure we are called once
|
// ensure we are called once
|
||||||
if (_mi_process_is_initialized) return;
|
static mi_atomic_once_t process_init;
|
||||||
|
if (!mi_atomic_once(&process_init)) return;
|
||||||
_mi_verbose_message("process init: 0x%zx\n", _mi_thread_id());
|
_mi_verbose_message("process init: 0x%zx\n", _mi_thread_id());
|
||||||
_mi_process_is_initialized = true;
|
_mi_process_is_initialized = true;
|
||||||
mi_process_setup_auto_thread_done();
|
mi_process_setup_auto_thread_done();
|
||||||
|
|
|
@ -420,7 +420,7 @@ __attribute__((constructor(0)))
|
||||||
#else
|
#else
|
||||||
__attribute__((constructor)) // seems not supported by g++-11 on the M1
|
__attribute__((constructor)) // seems not supported by g++-11 on the M1
|
||||||
#endif
|
#endif
|
||||||
static void _mi_macos_override_malloc() {
|
static void _mi_macos_override_malloc(void) {
|
||||||
malloc_zone_t* purgeable_zone = NULL;
|
malloc_zone_t* purgeable_zone = NULL;
|
||||||
|
|
||||||
#if defined(MAC_OS_X_VERSION_10_6) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6)
|
#if defined(MAC_OS_X_VERSION_10_6) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6)
|
||||||
|
|
Loading…
Add table
Reference in a new issue