41e0b857be
Header files are now self-contained, which makes the relationships between the files clearer, and crucially allows LSP tools like `clangd` to function correctly in all of our header files. I have verified that the headers are self-contained (aside from the various Windows shims) by compiling them as if they were C files – in a follow-up commit I plan to add this to CI to ensure we don't regress on this front.
43 lines
667 B
C
43 lines
667 B
C
#ifndef JEMALLOC_INTERNAL_SPIN_H
|
|
#define JEMALLOC_INTERNAL_SPIN_H
|
|
|
|
#include "jemalloc/internal/jemalloc_preamble.h"
|
|
|
|
#define SPIN_INITIALIZER {0U}
|
|
|
|
typedef struct {
|
|
unsigned iteration;
|
|
} spin_t;
|
|
|
|
static inline void
|
|
spin_cpu_spinwait(void) {
|
|
# if HAVE_CPU_SPINWAIT
|
|
CPU_SPINWAIT;
|
|
# else
|
|
volatile int x = 0;
|
|
x = x;
|
|
# endif
|
|
}
|
|
|
|
static inline void
|
|
spin_adaptive(spin_t *spin) {
|
|
volatile uint32_t i;
|
|
|
|
if (spin->iteration < 5) {
|
|
for (i = 0; i < (1U << spin->iteration); i++) {
|
|
spin_cpu_spinwait();
|
|
}
|
|
spin->iteration++;
|
|
} else {
|
|
#ifdef _WIN32
|
|
SwitchToThread();
|
|
#else
|
|
sched_yield();
|
|
#endif
|
|
}
|
|
}
|
|
|
|
#undef SPIN_INLINE
|
|
|
|
#endif /* JEMALLOC_INTERNAL_SPIN_H */
|