1 /******************************************************************************/
2 #ifdef JEMALLOC_H_TYPES
3 
4 typedef struct spin_s spin_t;
5 
6 #endif /* JEMALLOC_H_TYPES */
7 /******************************************************************************/
8 #ifdef JEMALLOC_H_STRUCTS
9 
10 struct spin_s {
11 	unsigned iteration;
12 };
13 
14 #endif /* JEMALLOC_H_STRUCTS */
15 /******************************************************************************/
16 #ifdef JEMALLOC_H_EXTERNS
17 
18 #endif /* JEMALLOC_H_EXTERNS */
19 /******************************************************************************/
20 #ifdef JEMALLOC_H_INLINES
21 
22 #ifndef JEMALLOC_ENABLE_INLINE
23 void	spin_init(spin_t *spin);
24 void	spin_adaptive(spin_t *spin);
25 #endif
26 
27 #if (defined(JEMALLOC_ENABLE_INLINE) || defined(JEMALLOC_SPIN_C_))
28 JEMALLOC_INLINE void
29 spin_init(spin_t *spin)
30 {
31 
32 	spin->iteration = 0;
33 }
34 
35 JEMALLOC_INLINE void
36 spin_adaptive(spin_t *spin)
37 {
38 	volatile uint64_t i;
39 
40 	for (i = 0; i < (KQU(1) << spin->iteration); i++)
41 		CPU_SPINWAIT;
42 
43 	if (spin->iteration < 63)
44 		spin->iteration++;
45 }
46 
47 #endif
48 
49 #endif /* JEMALLOC_H_INLINES */
50 /******************************************************************************/
51 
52