Skip to content

Commit

Permalink
Merge pull request #339 from devnexen/spin_impl_upd
Browse files Browse the repository at this point in the history
Restricts cpu yield instructions a little.
  • Loading branch information
daanx committed Dec 17, 2020
2 parents 33614cc + 33a10b4 commit 03503ea
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions include/mimalloc-atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,16 +282,22 @@ static inline void mi_atomic_yield(void) {
YieldProcessor();
}
#elif (defined(__GNUC__) || defined(__clang__)) && \
(defined(__x86_64__) || defined(__i386__) || defined(__arm__) || defined(__aarch64__))
(defined(__x86_64__) || defined(__i386__) || (defined(__arm__) && __ARM_ARCH__ >= 7) || defined(__aarch64__))
#if defined(__x86_64__) || defined(__i386__)
static inline void mi_atomic_yield(void) {
__asm__ volatile ("pause" ::: "memory");
}
#elif defined(__arm__) || defined(__aarch64__)
#elif (defined(__arm__) && __ARM_ARCH__ >= 7) || defined(__aarch64__)
static inline void mi_atomic_yield(void) {
__asm__ volatile("yield");
__asm__ volatile("yield" ::: "memory");
}
#endif
#elif defined(__sun)
// Fallback for other archs
#include <synch.h>
static inline void mi_atomic_yield(void) {
smt_pause();
}
#elif defined(__wasi__)
#include <sched.h>
static inline void mi_atomic_yield(void) {
Expand All @@ -305,4 +311,4 @@ static inline void mi_atomic_yield(void) {
#endif


#endif // __MIMALLOC_ATOMIC_H
#endif // __MIMALLOC_ATOMIC_H

0 comments on commit 03503ea

Please sign in to comment.