summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2019-11-18 10:49:28 -0500
committerMarge Bot <ben+marge-bot@smart-cactus.org>2019-11-23 18:57:12 -0500
commit0e6c204570f77950c9019faa50ff867c158249c5 (patch)
tree4614edb099bcad148a2b79da264903bb69e46be0 /includes
parente85c9b22e94cdc31d59ffc5ff72fcb5b4597d683 (diff)
downloadhaskell-0e6c204570f77950c9019faa50ff867c158249c5.tar.gz
rts: Consolidate spinlock implementation
Previously we had two distinct implementations: one with spinlock profiling and another without. This seems like needless duplication.
Diffstat (limited to 'includes')
-rw-r--r--includes/rts/SpinLock.h60
1 files changed, 13 insertions, 47 deletions
diff --git a/includes/rts/SpinLock.h b/includes/rts/SpinLock.h
index 037975268e..9f09099e2e 100644
--- a/includes/rts/SpinLock.h
+++ b/includes/rts/SpinLock.h
@@ -23,34 +23,33 @@
#if defined(THREADED_RTS)
-#if defined(PROF_SPIN)
typedef struct SpinLock_
{
StgWord lock;
+#if defined(PROF_SPIN)
StgWord64 spin; // incremented every time we spin in ACQUIRE_SPIN_LOCK
StgWord64 yield; // incremented every time we yield in ACQUIRE_SPIN_LOCK
-} SpinLock;
-#else
-typedef StgWord SpinLock;
#endif
-
-#if defined(PROF_SPIN)
+} SpinLock;
// PROF_SPIN enables counting the number of times we spin on a lock
+#if defined(PROF_SPIN)
+#define IF_PROF_SPIN(x) x
+#else
+#define IF_PROF_SPIN(x)
+#endif
// acquire spin lock
INLINE_HEADER void ACQUIRE_SPIN_LOCK(SpinLock * p)
{
- StgWord32 r = 0;
- uint32_t i;
do {
- for (i = 0; i < SPIN_COUNT; i++) {
- r = cas((StgVolatilePtr)&(p->lock), 1, 0);
+ for (uint32_t i = 0; i < SPIN_COUNT; i++) {
+ StgWord32 r = cas((StgVolatilePtr)&(p->lock), 1, 0);
if (r != 0) return;
- p->spin++;
+ IF_PROF_SPIN(p->spin++);
busy_wait_nop();
}
- p->yield++;
+ IF_PROF_SPIN(p->yield++);
yieldThread();
} while (1);
}
@@ -67,43 +66,10 @@ INLINE_HEADER void initSpinLock(SpinLock * p)
{
write_barrier();
p->lock = 1;
- p->spin = 0;
- p->yield = 0;
+ IF_PROF_SPIN(p->spin = 0);
+ IF_PROF_SPIN(p->yield = 0);
}
-#else
-
-// acquire spin lock
-INLINE_HEADER void ACQUIRE_SPIN_LOCK(SpinLock * p)
-{
- StgWord32 r = 0;
- uint32_t i;
- do {
- for (i = 0; i < SPIN_COUNT; i++) {
- r = cas((StgVolatilePtr)p, 1, 0);
- if (r != 0) return;
- busy_wait_nop();
- }
- yieldThread();
- } while (1);
-}
-
-// release spin lock
-INLINE_HEADER void RELEASE_SPIN_LOCK(SpinLock * p)
-{
- write_barrier();
- (*p) = 1;
-}
-
-// init spin lock
-INLINE_HEADER void initSpinLock(SpinLock * p)
-{
- write_barrier();
- (*p) = 1;
-}
-
-#endif /* PROF_SPIN */
-
#else /* !THREADED_RTS */
// Using macros here means we don't have to ensure the argument is in scope