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_init(spin_t *spin);
|
|
|
|
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_init(spin_t *spin) {
|
2017-01-11 10:06:31 +08:00
|
|
|
spin->iteration = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
JEMALLOC_INLINE void
|
2017-01-16 08:56:30 +08:00
|
|
|
spin_adaptive(spin_t *spin) {
|
2017-01-11 10:06:31 +08:00
|
|
|
volatile uint64_t i;
|
|
|
|
|
2017-01-16 08:56:30 +08:00
|
|
|
for (i = 0; i < (KQU(1) << spin->iteration); i++) {
|
2017-01-11 10:06:31 +08:00
|
|
|
CPU_SPINWAIT;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2017-01-11 10:06:31 +08:00
|
|
|
|
2017-01-16 08:56:30 +08:00
|
|
|
if (spin->iteration < 63) {
|
2017-01-11 10:06:31 +08:00
|
|
|
spin->iteration++;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2017-01-11 10:06:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* JEMALLOC_INTERNAL_SPIN_INLINES_H */
|