2017-01-11 10:06:31 +08:00
|
|
|
#ifndef JEMALLOC_INTERNAL_SPIN_INLINES_H
|
|
|
|
#define JEMALLOC_INTERNAL_SPIN_INLINES_H
|
|
|
|
|
|
|
|
#ifndef JEMALLOC_ENABLE_INLINE
|
|
|
|
void spin_adaptive(spin_t *spin);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if (defined(JEMALLOC_ENABLE_INLINE) || defined(JEMALLOC_SPIN_C_))
|
|
|
|
JEMALLOC_INLINE void
|
2017-01-16 08:56:30 +08:00
|
|
|
spin_adaptive(spin_t *spin) {
|
2017-02-09 02:30:44 +08:00
|
|
|
volatile uint32_t i;
|
2017-01-11 10:06:31 +08:00
|
|
|
|
2017-02-09 02:30:44 +08:00
|
|
|
if (spin->iteration < 5) {
|
|
|
|
for (i = 0; i < (1U << spin->iteration); i++) {
|
|
|
|
CPU_SPINWAIT;
|
|
|
|
}
|
2017-01-11 10:06:31 +08:00
|
|
|
spin->iteration++;
|
2017-02-09 02:30:44 +08:00
|
|
|
} else {
|
|
|
|
#ifdef _WIN32
|
|
|
|
SwitchToThread();
|
|
|
|
#else
|
|
|
|
sched_yield();
|
|
|
|
#endif
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2017-01-11 10:06:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* JEMALLOC_INTERNAL_SPIN_INLINES_H */
|