summaryrefslogtreecommitdiffstats
path: root/include/jemalloc/internal/spin.h
diff options
context:
space:
mode:
authorJason Evans <jasone@canonware.com>2017-06-13 19:49:58 (GMT)
committerJason Evans <jasone@canonware.com>2017-06-13 19:51:09 (GMT)
commit5018fe3f0979b7f9db9930accdf7ee31071fd703 (patch)
tree894055b5ff4ccde3d9d782861d45af4664f12ad2 /include/jemalloc/internal/spin.h
parent04380e79f1e2428bd0ad000bbc6e3d2dfc6b66a5 (diff)
parentba29113e5a58caeb6b4a65b1db6d8efae79cae45 (diff)
downloadjemalloc-5.0.0.zip
jemalloc-5.0.0.tar.gz
jemalloc-5.0.0.tar.bz2
Merge branch 'dev'5.0.0
Diffstat (limited to 'include/jemalloc/internal/spin.h')
-rw-r--r--include/jemalloc/internal/spin.h67
1 files changed, 26 insertions, 41 deletions
diff --git a/include/jemalloc/internal/spin.h b/include/jemalloc/internal/spin.h
index 9ef5ceb..e2afc98 100644
--- a/include/jemalloc/internal/spin.h
+++ b/include/jemalloc/internal/spin.h
@@ -1,51 +1,36 @@
-/******************************************************************************/
-#ifdef JEMALLOC_H_TYPES
+#ifndef JEMALLOC_INTERNAL_SPIN_H
+#define JEMALLOC_INTERNAL_SPIN_H
-typedef struct spin_s spin_t;
-
-#endif /* JEMALLOC_H_TYPES */
-/******************************************************************************/
-#ifdef JEMALLOC_H_STRUCTS
-
-struct spin_s {
- unsigned iteration;
-};
-
-#endif /* JEMALLOC_H_STRUCTS */
-/******************************************************************************/
-#ifdef JEMALLOC_H_EXTERNS
-
-#endif /* JEMALLOC_H_EXTERNS */
-/******************************************************************************/
-#ifdef JEMALLOC_H_INLINES
-
-#ifndef JEMALLOC_ENABLE_INLINE
-void spin_init(spin_t *spin);
-void spin_adaptive(spin_t *spin);
+#ifdef JEMALLOC_SPIN_C_
+# define SPIN_INLINE extern inline
+#else
+# define SPIN_INLINE inline
#endif
-#if (defined(JEMALLOC_ENABLE_INLINE) || defined(JEMALLOC_SPIN_C_))
-JEMALLOC_INLINE void
-spin_init(spin_t *spin)
-{
+#define SPIN_INITIALIZER {0U}
- spin->iteration = 0;
-}
-
-JEMALLOC_INLINE void
-spin_adaptive(spin_t *spin)
-{
- volatile uint64_t i;
+typedef struct {
+ unsigned iteration;
+} spin_t;
- for (i = 0; i < (KQU(1) << spin->iteration); i++)
- CPU_SPINWAIT;
+SPIN_INLINE void
+spin_adaptive(spin_t *spin) {
+ volatile uint32_t i;
- if (spin->iteration < 63)
+ if (spin->iteration < 5) {
+ for (i = 0; i < (1U << spin->iteration); i++) {
+ CPU_SPINWAIT;
+ }
spin->iteration++;
-}
-
+ } else {
+#ifdef _WIN32
+ SwitchToThread();
+#else
+ sched_yield();
#endif
+ }
+}
-#endif /* JEMALLOC_H_INLINES */
-/******************************************************************************/
+#undef SPIN_INLINE
+#endif /* JEMALLOC_INTERNAL_SPIN_H */