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

Commit

Permalink
Fixes in allocator
Browse files Browse the repository at this point in the history
  • Loading branch information
Elena Lepilkina authored and Elena Lepilkina committed Dec 20, 2019
1 parent 2e7571d commit 01a719e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
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();
#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

0 comments on commit 01a719e

Please sign in to comment.