1 #ifndef JEMALLOC_INTERNAL_SPIN_H 2 #define JEMALLOC_INTERNAL_SPIN_H 3 4 #define SPIN_INITIALIZER {0U} 5 6 typedef struct { 7 unsigned iteration; 8 } spin_t; 9 10 static inline void spin_cpu_spinwait()11spin_cpu_spinwait() { 12 # if HAVE_CPU_SPINWAIT 13 CPU_SPINWAIT; 14 # else 15 volatile int x = 0; 16 x = x; 17 # endif 18 } 19 20 static inline void spin_adaptive(spin_t * spin)21spin_adaptive(spin_t *spin) { 22 volatile uint32_t i; 23 24 if (spin->iteration < 5) { 25 for (i = 0; i < (1U << spin->iteration); i++) { 26 spin_cpu_spinwait(); 27 } 28 spin->iteration++; 29 } else { 30 #ifdef _WIN32 31 SwitchToThread(); 32 #else 33 sched_yield(); 34 #endif 35 } 36 } 37 38 #undef SPIN_INLINE 39 40 #endif /* JEMALLOC_INTERNAL_SPIN_H */ 41