mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-05-06 15:29:31 +03:00
fix msvc compilation in C mode
This commit is contained in:
parent
2383b72ef7
commit
ccc65d2fd9
6 changed files with 22 additions and 10 deletions
|
@ -313,10 +313,10 @@
|
||||||
<WholeProgramOptimization>false</WholeProgramOptimization>
|
<WholeProgramOptimization>false</WholeProgramOptimization>
|
||||||
<BufferSecurityCheck>false</BufferSecurityCheck>
|
<BufferSecurityCheck>false</BufferSecurityCheck>
|
||||||
<InlineFunctionExpansion>Default</InlineFunctionExpansion>
|
<InlineFunctionExpansion>Default</InlineFunctionExpansion>
|
||||||
<CompileAs>CompileAsC</CompileAs>
|
<CompileAs>CompileAsCpp</CompileAs>
|
||||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||||
<EnableEnhancedInstructionSet>StreamingSIMDExtensions</EnableEnhancedInstructionSet>
|
<EnableEnhancedInstructionSet>AdvancedVectorExtensions2</EnableEnhancedInstructionSet>
|
||||||
<AdditionalOptions>/Zc:__cplusplus %(AdditionalOptions)</AdditionalOptions>
|
<AdditionalOptions>/Zc:__cplusplus %(AdditionalOptions)</AdditionalOptions>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
|
|
|
@ -271,6 +271,7 @@ static inline int64_t mi_atomic_addi64_relaxed(volatile _Atomic(int64_t)*p, int6
|
||||||
return current;
|
return current;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void mi_atomic_void_addi64_relaxed(volatile int64_t* p, const volatile int64_t* padd) {
|
static inline void mi_atomic_void_addi64_relaxed(volatile int64_t* p, const volatile int64_t* padd) {
|
||||||
const int64_t add = *padd;
|
const int64_t add = *padd;
|
||||||
if (add != 0) {
|
if (add != 0) {
|
||||||
|
|
|
@ -22,6 +22,7 @@ terms of the MIT license. A copy of the license can be found in the file
|
||||||
#include <mimalloc-stats.h>
|
#include <mimalloc-stats.h>
|
||||||
#include <stddef.h> // ptrdiff_t
|
#include <stddef.h> // ptrdiff_t
|
||||||
#include <stdint.h> // uintptr_t, uint16_t, etc
|
#include <stdint.h> // uintptr_t, uint16_t, etc
|
||||||
|
#include <limits.h> // SIZE_MAX etc.
|
||||||
#include <errno.h> // error codes
|
#include <errno.h> // error codes
|
||||||
#include "bits.h" // size defines (MI_INTPTR_SIZE etc), bit operations
|
#include "bits.h" // size defines (MI_INTPTR_SIZE etc), bit operations
|
||||||
#include "atomic.h" // _Atomic primitives
|
#include "atomic.h" // _Atomic primitives
|
||||||
|
|
|
@ -1684,7 +1684,7 @@ static bool mi_arena_try_purge(mi_arena_t* arena, mi_msecs_t now, bool force)
|
||||||
if (!force && (expire == 0 || expire > now)) return false;
|
if (!force && (expire == 0 || expire > now)) return false;
|
||||||
|
|
||||||
// reset expire
|
// reset expire
|
||||||
mi_atomic_store_release(&arena->purge_expire, (mi_msecs_t)0);
|
mi_atomic_storei64_release(&arena->purge_expire, (mi_msecs_t)0);
|
||||||
mi_subproc_stat_counter_increase(arena->subproc, arena_purges, 1);
|
mi_subproc_stat_counter_increase(arena->subproc, arena_purges, 1);
|
||||||
|
|
||||||
// go through all purge info's (with max MI_BFIELD_BITS ranges at a time)
|
// go through all purge info's (with max MI_BFIELD_BITS ranges at a time)
|
||||||
|
@ -1706,7 +1706,7 @@ static void mi_arenas_try_purge(bool force, bool visit_all, mi_tld_t* tld)
|
||||||
// check if any arena needs purging?
|
// check if any arena needs purging?
|
||||||
mi_subproc_t* subproc = tld->subproc;
|
mi_subproc_t* subproc = tld->subproc;
|
||||||
const mi_msecs_t now = _mi_clock_now();
|
const mi_msecs_t now = _mi_clock_now();
|
||||||
const mi_msecs_t arenas_expire = mi_atomic_load_acquire(&subproc->purge_expire);
|
const mi_msecs_t arenas_expire = mi_atomic_loadi64_acquire(&subproc->purge_expire);
|
||||||
if (!visit_all && !force && (arenas_expire == 0 || arenas_expire > now)) return;
|
if (!visit_all && !force && (arenas_expire == 0 || arenas_expire > now)) return;
|
||||||
|
|
||||||
const size_t max_arena = mi_arenas_get_count(subproc);
|
const size_t max_arena = mi_arenas_get_count(subproc);
|
||||||
|
@ -1717,7 +1717,7 @@ static void mi_arenas_try_purge(bool force, bool visit_all, mi_tld_t* tld)
|
||||||
mi_atomic_guard(&purge_guard)
|
mi_atomic_guard(&purge_guard)
|
||||||
{
|
{
|
||||||
// increase global expire: at most one purge per delay cycle
|
// increase global expire: at most one purge per delay cycle
|
||||||
if (arenas_expire > now) { mi_atomic_store_release(&subproc->purge_expire, now + (delay/10)); }
|
if (arenas_expire > now) { mi_atomic_storei64_release(&subproc->purge_expire, now + (delay/10)); }
|
||||||
const size_t arena_start = tld->thread_seq % max_arena;
|
const size_t arena_start = tld->thread_seq % max_arena;
|
||||||
size_t max_purge_count = (visit_all ? max_arena : (max_arena/4)+1);
|
size_t max_purge_count = (visit_all ? max_arena : (max_arena/4)+1);
|
||||||
bool all_visited = true;
|
bool all_visited = true;
|
||||||
|
@ -1738,7 +1738,7 @@ static void mi_arenas_try_purge(bool force, bool visit_all, mi_tld_t* tld)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (all_visited && !any_purged) {
|
if (all_visited && !any_purged) {
|
||||||
mi_atomic_store_release(&subproc->purge_expire, 0);
|
mi_atomic_storei64_release(&subproc->purge_expire, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
16
src/bitmap.h
16
src/bitmap.h
|
@ -71,8 +71,18 @@ typedef size_t mi_bfield_t;
|
||||||
#define MI_BCHUNK_FIELDS (MI_BCHUNK_BITS / MI_BFIELD_BITS) // 8 on both 64- and 32-bit
|
#define MI_BCHUNK_FIELDS (MI_BCHUNK_BITS / MI_BFIELD_BITS) // 8 on both 64- and 32-bit
|
||||||
|
|
||||||
|
|
||||||
|
// some compiler (msvc in C mode) cannot have expressions in the alignment attribute
|
||||||
|
#if MI_BCHUNK_SIZE==64
|
||||||
|
#define mi_decl_bchunk_align mi_decl_align(64)
|
||||||
|
#elif MI_BCHUNK_SIZE==32
|
||||||
|
#define mi_decl_bchunk_align mi_decl_align(32)
|
||||||
|
#else
|
||||||
|
#define mi_decl_bchunk_align mi_decl_align(MI_BCHUNK_SIZE)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// A bitmap chunk contains 512 bits on 64-bit (256 on 32-bit)
|
// A bitmap chunk contains 512 bits on 64-bit (256 on 32-bit)
|
||||||
typedef mi_decl_align(MI_BCHUNK_SIZE) struct mi_bchunk_s {
|
typedef mi_decl_bchunk_align struct mi_bchunk_s {
|
||||||
_Atomic(mi_bfield_t) bfields[MI_BCHUNK_FIELDS];
|
_Atomic(mi_bfield_t) bfields[MI_BCHUNK_FIELDS];
|
||||||
} mi_bchunk_t;
|
} mi_bchunk_t;
|
||||||
|
|
||||||
|
@ -96,7 +106,7 @@ typedef mi_bchunk_t mi_bchunkmap_t;
|
||||||
|
|
||||||
|
|
||||||
// An atomic bitmap
|
// An atomic bitmap
|
||||||
typedef mi_decl_align(MI_BCHUNK_SIZE) struct mi_bitmap_s {
|
typedef mi_decl_bchunk_align struct mi_bitmap_s {
|
||||||
_Atomic(size_t) chunk_count; // total count of chunks (0 < N <= MI_BCHUNKMAP_BITS)
|
_Atomic(size_t) chunk_count; // total count of chunks (0 < N <= MI_BCHUNKMAP_BITS)
|
||||||
size_t _padding[MI_BCHUNK_SIZE/MI_SIZE_SIZE - 1]; // suppress warning on msvc
|
size_t _padding[MI_BCHUNK_SIZE/MI_SIZE_SIZE - 1]; // suppress warning on msvc
|
||||||
mi_bchunkmap_t chunkmap;
|
mi_bchunkmap_t chunkmap;
|
||||||
|
@ -243,7 +253,7 @@ static inline mi_bbin_t mi_bbin_of(size_t slice_count) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// An atomic "binned" bitmap for the free slices where we keep chunks reserved for particalar size classes
|
// An atomic "binned" bitmap for the free slices where we keep chunks reserved for particalar size classes
|
||||||
typedef mi_decl_align(MI_BCHUNK_SIZE) struct mi_bbitmap_s {
|
typedef mi_decl_bchunk_align struct mi_bbitmap_s {
|
||||||
_Atomic(size_t) chunk_count; // total count of chunks (0 < N <= MI_BCHUNKMAP_BITS)
|
_Atomic(size_t) chunk_count; // total count of chunks (0 < N <= MI_BCHUNKMAP_BITS)
|
||||||
_Atomic(size_t) chunk_max_accessed; // max chunk index that was once cleared or set
|
_Atomic(size_t) chunk_max_accessed; // max chunk index that was once cleared or set
|
||||||
size_t _padding[MI_BCHUNK_SIZE/MI_SIZE_SIZE - 2]; // suppress warning on msvc
|
size_t _padding[MI_BCHUNK_SIZE/MI_SIZE_SIZE - 2]; // suppress warning on msvc
|
||||||
|
|
|
@ -848,7 +848,7 @@ bool _mi_prim_thread_is_in_threadpool(void) {
|
||||||
if (win_major_version >= 6) {
|
if (win_major_version >= 6) {
|
||||||
// check if this thread belongs to a windows threadpool
|
// check if this thread belongs to a windows threadpool
|
||||||
// see: <https://www.geoffchappell.com/studies/windows/km/ntoskrnl/inc/api/pebteb/teb/index.htm>
|
// see: <https://www.geoffchappell.com/studies/windows/km/ntoskrnl/inc/api/pebteb/teb/index.htm>
|
||||||
_TEB* const teb = NtCurrentTeb();
|
struct _TEB* const teb = NtCurrentTeb();
|
||||||
void* const pool_data = *((void**)((uint8_t*)teb + (MI_SIZE_BITS == 32 ? 0x0F90 : 0x1778)));
|
void* const pool_data = *((void**)((uint8_t*)teb + (MI_SIZE_BITS == 32 ? 0x0F90 : 0x1778)));
|
||||||
return (pool_data != NULL);
|
return (pool_data != NULL);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue