Merge branch 'dev' into dev-slice
This commit is contained in:
commit
131b62283b
@ -23,10 +23,15 @@ terms of the MIT license. A copy of the license can be found in the file
|
|||||||
#define _Atomic(tp) std::atomic<tp>
|
#define _Atomic(tp) std::atomic<tp>
|
||||||
#define mi_atomic(name) std::atomic_##name
|
#define mi_atomic(name) std::atomic_##name
|
||||||
#define mi_memory_order(name) std::memory_order_##name
|
#define mi_memory_order(name) std::memory_order_##name
|
||||||
|
#if !defined(ATOMIC_VAR_INIT) || (__cplusplus >= 202002L) // c++20, see issue #571
|
||||||
|
#define MI_ATOMIC_VAR_INIT(x) x
|
||||||
|
#else
|
||||||
|
#define MI_ATOMIC_VAR_INIT(x) ATOMIC_VAR_INIT(x)
|
||||||
|
#endif
|
||||||
#elif defined(_MSC_VER)
|
#elif defined(_MSC_VER)
|
||||||
// Use MSVC C wrapper for C11 atomics
|
// Use MSVC C wrapper for C11 atomics
|
||||||
#define _Atomic(tp) tp
|
#define _Atomic(tp) tp
|
||||||
#define ATOMIC_VAR_INIT(x) x
|
#define MI_ATOMIC_VAR_INIT(x) x
|
||||||
#define mi_atomic(name) mi_atomic_##name
|
#define mi_atomic(name) mi_atomic_##name
|
||||||
#define mi_memory_order(name) mi_memory_order_##name
|
#define mi_memory_order(name) mi_memory_order_##name
|
||||||
#else
|
#else
|
||||||
@ -34,6 +39,7 @@ terms of the MIT license. A copy of the license can be found in the file
|
|||||||
#include <stdatomic.h>
|
#include <stdatomic.h>
|
||||||
#define mi_atomic(name) atomic_##name
|
#define mi_atomic(name) atomic_##name
|
||||||
#define mi_memory_order(name) memory_order_##name
|
#define mi_memory_order(name) memory_order_##name
|
||||||
|
#define MI_ATOMIC_VAR_INIT(x) ATOMIC_VAR_INIT(x)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Various defines for all used memory orders in mimalloc
|
// Various defines for all used memory orders in mimalloc
|
||||||
|
10
src/init.c
10
src/init.c
@ -25,8 +25,8 @@ const mi_page_t _mi_page_empty = {
|
|||||||
0, // used
|
0, // used
|
||||||
0, // xblock_size
|
0, // xblock_size
|
||||||
NULL, // local_free
|
NULL, // local_free
|
||||||
ATOMIC_VAR_INIT(0), // xthread_free
|
MI_ATOMIC_VAR_INIT(0), // xthread_free
|
||||||
ATOMIC_VAR_INIT(0), // xheap
|
MI_ATOMIC_VAR_INIT(0), // xheap
|
||||||
NULL, NULL
|
NULL, NULL
|
||||||
#if MI_INTPTR_SIZE==8
|
#if MI_INTPTR_SIZE==8
|
||||||
, { 0 } // padding
|
, { 0 } // padding
|
||||||
@ -106,7 +106,7 @@ mi_decl_cache_align const mi_heap_t _mi_heap_empty = {
|
|||||||
NULL,
|
NULL,
|
||||||
MI_SMALL_PAGES_EMPTY,
|
MI_SMALL_PAGES_EMPTY,
|
||||||
MI_PAGE_QUEUES_EMPTY,
|
MI_PAGE_QUEUES_EMPTY,
|
||||||
ATOMIC_VAR_INIT(NULL),
|
MI_ATOMIC_VAR_INIT(NULL),
|
||||||
0, // tid
|
0, // tid
|
||||||
0, // cookie
|
0, // cookie
|
||||||
{ 0, 0 }, // keys
|
{ 0, 0 }, // keys
|
||||||
@ -146,7 +146,7 @@ mi_heap_t _mi_heap_main = {
|
|||||||
&tld_main,
|
&tld_main,
|
||||||
MI_SMALL_PAGES_EMPTY,
|
MI_SMALL_PAGES_EMPTY,
|
||||||
MI_PAGE_QUEUES_EMPTY,
|
MI_PAGE_QUEUES_EMPTY,
|
||||||
ATOMIC_VAR_INIT(NULL),
|
MI_ATOMIC_VAR_INIT(NULL),
|
||||||
0, // thread id
|
0, // thread id
|
||||||
0, // initial cookie
|
0, // initial cookie
|
||||||
{ 0, 0 }, // the key of the main heap can be fixed (unlike page keys that need to be secure!)
|
{ 0, 0 }, // the key of the main heap can be fixed (unlike page keys that need to be secure!)
|
||||||
@ -352,7 +352,7 @@ bool _mi_is_main_thread(void) {
|
|||||||
return (_mi_heap_main.thread_id==0 || _mi_heap_main.thread_id == _mi_thread_id());
|
return (_mi_heap_main.thread_id==0 || _mi_heap_main.thread_id == _mi_thread_id());
|
||||||
}
|
}
|
||||||
|
|
||||||
static _Atomic(size_t) thread_count = ATOMIC_VAR_INIT(1);
|
static _Atomic(size_t) thread_count = MI_ATOMIC_VAR_INIT(1);
|
||||||
|
|
||||||
size_t _mi_current_thread_count(void) {
|
size_t _mi_current_thread_count(void) {
|
||||||
return mi_atomic_load_relaxed(&thread_count);
|
return mi_atomic_load_relaxed(&thread_count);
|
||||||
|
2
src/os.c
2
src/os.c
@ -983,7 +983,7 @@ static bool mi_os_resetx(void* addr, size_t size, bool reset, mi_stats_t* stats)
|
|||||||
if (p != start) return false;
|
if (p != start) return false;
|
||||||
#else
|
#else
|
||||||
#if defined(MADV_FREE)
|
#if defined(MADV_FREE)
|
||||||
static _Atomic(size_t) advice = ATOMIC_VAR_INIT(MADV_FREE);
|
static _Atomic(size_t) advice = MI_ATOMIC_VAR_INIT(MADV_FREE);
|
||||||
int oadvice = (int)mi_atomic_load_relaxed(&advice);
|
int oadvice = (int)mi_atomic_load_relaxed(&advice);
|
||||||
int err;
|
int err;
|
||||||
while ((err = mi_madvise(start, csize, oadvice)) != 0 && errno == EAGAIN) { errno = 0; };
|
while ((err = mi_madvise(start, csize, oadvice)) != 0 && errno == EAGAIN) { errno = 0; };
|
||||||
|
Loading…
Reference in New Issue
Block a user