Skip to content
This repository has been archived by the owner on Aug 10, 2021. It is now read-only.

Mimalloc allocator integration #3704

Merged
merged 3 commits into from
Dec 27, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions runtime/src/mimalloc/c/include/mimalloc-atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,22 @@ static inline void mi_atomic_write(volatile _Atomic(uintptr_t)* p, uintptr_t x)
asm volatile ("pause" ::: "memory");
}
#elif defined(__arm__) || defined(__aarch64__)
#if defined(KONAN_MI_MALLOC)
#if defined(__arm__)
#include <sched.h>
static inline void mi_atomic_yield(void) {
sched_yield();
}
#else
static inline void mi_atomic_yield(void) {
asm volatile("yield");
}
#endif
#else
static inline void mi_atomic_yield(void) {
asm volatile("yield");
}
#endif
#endif
#elif defined(__wasi__)
#include <sched.h>
Expand Down
15 changes: 14 additions & 1 deletion runtime/src/mimalloc/c/include/mimalloc-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -457,14 +457,27 @@ static inline uintptr_t _mi_thread_id(void) mi_attr_noexcept {
}
#elif (defined(__GNUC__) || defined(__clang__)) && \
(defined(__x86_64__) || defined(__i386__) || defined(__arm__) || defined(__aarch64__))
#if defined(KONAN_MI_MALLOC)
#include <pthread.h>
pthread_t pthread_self(void);
#endif
// TLS register on x86 is in the FS or GS register
// see: https://akkadia.org/drepper/tls.pdf
static inline uintptr_t _mi_thread_id(void) mi_attr_noexcept {
uintptr_t tid;
#if defined(__i386__)
__asm__("movl %%gs:0, %0" : "=r" (tid) : : ); // 32-bit always uses GS
#elif defined(__MACH__)
__asm__("movq %%gs:0, %0" : "=r" (tid) : : ); // x86_64 macOS uses GS
#if defined(KONAN_MI_MALLOC)
#include <TargetConditionals.h>
#if TARGET_OS_EMBEDDED // iOS/tvOS/watchOS devices.
tid = pthread_self();
LepilkinaElena marked this conversation as resolved.
Show resolved Hide resolved
#else
__asm__("movq %%gs:0, %0" : "=r" (tid) : : ); // x86_64 macOS uses GS
#endif
#else
__asm__("movq %%gs:0, %0" : "=r" (tid) : : ); // x86_64 macOS uses GS
#endif
#elif defined(__x86_64__)
__asm__("movq %%fs:0, %0" : "=r" (tid) : : ); // x86_64 Linux, BSD uses FS
#elif defined(__arm__)
Expand Down
4 changes: 3 additions & 1 deletion runtime/src/mimalloc/c/include/mimalloc-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ terms of the MIT license. A copy of the license can be found in the file
// ------------------------------------------------------

// Define NDEBUG in the release version to disable assertions.
// #define NDEBUG
#if !defined(KONAN_MI_MALLOC)
#define NDEBUG
#endif

// Define MI_STAT as 1 to maintain statistics; set it to 2 to have detailed statistics (but costs some performance).
// #define MI_STAT 1
Expand Down