mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-05-06 23:39:31 +03:00
merge from dev
This commit is contained in:
commit
d4a7c0ffcc
4 changed files with 43 additions and 44 deletions
|
@ -132,7 +132,7 @@ static inline void mi_atomic_maxi64_relaxed(volatile int64_t* p, int64_t x) {
|
||||||
|
|
||||||
#elif defined(_MSC_VER)
|
#elif defined(_MSC_VER)
|
||||||
|
|
||||||
// MSVC C compilation wrapper that uses Interlocked operations to model C11 atomics.
|
// Legacy MSVC plain C compilation wrapper that uses Interlocked operations to model C11 atomics.
|
||||||
#ifndef WIN32_LEAN_AND_MEAN
|
#ifndef WIN32_LEAN_AND_MEAN
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
#endif
|
#endif
|
||||||
|
@ -201,7 +201,7 @@ static inline uintptr_t mi_atomic_load_explicit(_Atomic(uintptr_t) const* p, mi_
|
||||||
#else
|
#else
|
||||||
uintptr_t x = *p;
|
uintptr_t x = *p;
|
||||||
if (mo > mi_memory_order_relaxed) {
|
if (mo > mi_memory_order_relaxed) {
|
||||||
while (!mi_atomic_compare_exchange_weak_explicit(p, &x, x, mo, mi_memory_order_relaxed)) { /* nothing */ };
|
while (!mi_atomic_compare_exchange_weak_explicit((_Atomic(uintptr_t)*)p, &x, x, mo, mi_memory_order_relaxed)) { /* nothing */ };
|
||||||
}
|
}
|
||||||
return x;
|
return x;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -14,8 +14,8 @@ terms of the MIT license. A copy of the license can be found in the file
|
||||||
// functions and macros.
|
// functions and macros.
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
#include "mimalloc/types.h"
|
#include "types.h"
|
||||||
#include "mimalloc/track.h"
|
#include "track.h"
|
||||||
|
|
||||||
#if (MI_DEBUG>0)
|
#if (MI_DEBUG>0)
|
||||||
#define mi_trace_message(...) _mi_trace_message(__VA_ARGS__)
|
#define mi_trace_message(...) _mi_trace_message(__VA_ARGS__)
|
||||||
|
|
|
@ -24,7 +24,7 @@ terms of the MIT license. A copy of the license can be found in the file
|
||||||
|
|
||||||
#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 "mimalloc/atomic.h" // _Atomic
|
#include "atomic.h" // _Atomic
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#pragma warning(disable:4214) // bitfield is not int
|
#pragma warning(disable:4214) // bitfield is not int
|
||||||
|
|
|
@ -57,7 +57,7 @@ terms of the MIT license. A copy of the license can be found in the file
|
||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(__HAIKU__) && !defined(__APPLE__) && !defined(__CYGWIN__) && !defined(__OpenBSD__) && !defined(__sun)
|
#if defined(__linux__) || defined(__FreeBSD__)
|
||||||
#define MI_HAS_SYSCALL_H
|
#define MI_HAS_SYSCALL_H
|
||||||
#include <sys/syscall.h>
|
#include <sys/syscall.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -67,37 +67,36 @@ terms of the MIT license. A copy of the license can be found in the file
|
||||||
// Use syscalls for some primitives to allow for libraries that override open/read/close etc.
|
// Use syscalls for some primitives to allow for libraries that override open/read/close etc.
|
||||||
// and do allocation themselves; using syscalls prevents recursion when mimalloc is
|
// and do allocation themselves; using syscalls prevents recursion when mimalloc is
|
||||||
// still initializing (issue #713)
|
// still initializing (issue #713)
|
||||||
|
// Declare inline to avoid unused function warnings.
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
#if defined(MI_HAS_SYSCALL_H) && defined(SYS_open) && defined(SYS_close) && defined(SYS_read) && defined(SYS_access)
|
#if defined(MI_HAS_SYSCALL_H) && defined(SYS_open) && defined(SYS_close) && defined(SYS_read) && defined(SYS_access)
|
||||||
|
|
||||||
static int mi_prim_open(const char* fpath, int open_flags) {
|
static inline int mi_prim_open(const char* fpath, int open_flags) {
|
||||||
return syscall(SYS_open,fpath,open_flags,0);
|
return syscall(SYS_open,fpath,open_flags,0);
|
||||||
}
|
}
|
||||||
static ssize_t mi_prim_read(int fd, void* buf, size_t bufsize) {
|
static inline ssize_t mi_prim_read(int fd, void* buf, size_t bufsize) {
|
||||||
return syscall(SYS_read,fd,buf,bufsize);
|
return syscall(SYS_read,fd,buf,bufsize);
|
||||||
}
|
}
|
||||||
static int mi_prim_close(int fd) {
|
static inline int mi_prim_close(int fd) {
|
||||||
return syscall(SYS_close,fd);
|
return syscall(SYS_close,fd);
|
||||||
}
|
}
|
||||||
static int mi_prim_access(const char *fpath, int mode) {
|
static inline int mi_prim_access(const char *fpath, int mode) {
|
||||||
return syscall(SYS_access,fpath,mode);
|
return syscall(SYS_access,fpath,mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif !defined(__sun) && \
|
#else
|
||||||
(!defined(__APPLE__) || (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_7)) // avoid unused warnings on macOS and Solaris
|
|
||||||
|
|
||||||
static int mi_prim_open(const char* fpath, int open_flags) {
|
static inline int mi_prim_open(const char* fpath, int open_flags) {
|
||||||
return open(fpath,open_flags);
|
return open(fpath,open_flags);
|
||||||
}
|
}
|
||||||
static ssize_t mi_prim_read(int fd, void* buf, size_t bufsize) {
|
static inline ssize_t mi_prim_read(int fd, void* buf, size_t bufsize) {
|
||||||
return read(fd,buf,bufsize);
|
return read(fd,buf,bufsize);
|
||||||
}
|
}
|
||||||
static int mi_prim_close(int fd) {
|
static inline int mi_prim_close(int fd) {
|
||||||
return close(fd);
|
return close(fd);
|
||||||
}
|
}
|
||||||
static int mi_prim_access(const char *fpath, int mode) {
|
static inline int mi_prim_access(const char *fpath, int mode) {
|
||||||
return access(fpath,mode);
|
return access(fpath,mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,7 +198,7 @@ static void* unix_mmap_prim(void* addr, size_t size, size_t try_alignment, int p
|
||||||
p = mmap(addr, size, protect_flags, flags | MAP_ALIGNED(n), fd, 0);
|
p = mmap(addr, size, protect_flags, flags | MAP_ALIGNED(n), fd, 0);
|
||||||
if (p==MAP_FAILED || !_mi_is_aligned(p,try_alignment)) {
|
if (p==MAP_FAILED || !_mi_is_aligned(p,try_alignment)) {
|
||||||
int err = errno;
|
int err = errno;
|
||||||
_mi_warning_message("unable to directly request aligned OS memory (error: %d (0x%x), size: 0x%zx bytes, alignment: 0x%zx, hint address: %p)\n", err, err, size, try_alignment, addr);
|
_mi_trace_message("unable to directly request aligned OS memory (error: %d (0x%x), size: 0x%zx bytes, alignment: 0x%zx, hint address: %p)\n", err, err, size, try_alignment, addr);
|
||||||
}
|
}
|
||||||
if (p!=MAP_FAILED) return p;
|
if (p!=MAP_FAILED) return p;
|
||||||
// fall back to regular mmap
|
// fall back to regular mmap
|
||||||
|
@ -224,7 +223,7 @@ static void* unix_mmap_prim(void* addr, size_t size, size_t try_alignment, int p
|
||||||
#else
|
#else
|
||||||
int err = errno;
|
int err = errno;
|
||||||
#endif
|
#endif
|
||||||
_mi_warning_message("unable to directly request hinted aligned OS memory (error: %d (0x%x), size: 0x%zx bytes, alignment: 0x%zx, hint address: %p)\n", err, err, size, try_alignment, hint);
|
_mi_trace_message("unable to directly request hinted aligned OS memory (error: %d (0x%x), size: 0x%zx bytes, alignment: 0x%zx, hint address: %p)\n", err, err, size, try_alignment, hint);
|
||||||
}
|
}
|
||||||
if (p!=MAP_FAILED) return p;
|
if (p!=MAP_FAILED) return p;
|
||||||
// fall back to regular mmap
|
// fall back to regular mmap
|
||||||
|
|
Loading…
Add table
Reference in a new issue