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
11 spin_adaptive(spin_t *spin) {
12 	volatile uint32_t i;
13 
14 	if (spin->iteration < 5) {
15 		for (i = 0; i < (1U << spin->iteration); i++) {
16 			CPU_SPINWAIT;
17 		}
18 		spin->iteration++;
19 	} else {
20 #ifdef _WIN32
21 		SwitchToThread();
22 #else
23 		sched_yield();
24 #endif
25 	}
26 }
27 
28 #undef SPIN_INLINE
29 
30 #endif /* JEMALLOC_INTERNAL_SPIN_H */
31