summaryrefslogtreecommitdiff
path: root/rts/Timer.c
diff options
context:
space:
mode:
authorCheng Shao <astrohavoc@gmail.com>2022-10-23 12:15:38 +0000
committerMarge Bot <ben+marge-bot@smart-cactus.org>2022-11-11 00:26:55 -0500
commit65b82542b6b031cb63933944e35de317ffed7a06 (patch)
tree0aec2fd7aafc1b76228c432e5ad6ced39aacdaac /rts/Timer.c
parent65ba328539c3a6f0fa26a7dc182c2de450d836ea (diff)
downloadhaskell-65b82542b6b031cb63933944e35de317ffed7a06.tar.gz
rts: no timer for wasm32
Due to the lack of threads, on wasm32 there can't be a background timer that periodically resets the context switch flag. This patch disables timer for wasm32, and also makes the scheduler default to -C0 on wasm32 to avoid starving threads.
Diffstat (limited to 'rts/Timer.c')
-rw-r--r--rts/Timer.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/rts/Timer.c b/rts/Timer.c
index e6666856a6..332334129d 100644
--- a/rts/Timer.c
+++ b/rts/Timer.c
@@ -26,6 +26,11 @@
#include "RtsSignals.h"
#include "rts/EventLogWriter.h"
+// See Note [No timer on wasm32]
+#if !defined(wasm32_HOST_ARCH)
+#define HAVE_PREEMPTION
+#endif
+
// This global counter is used to allow multiple threads to stop the
// timer temporarily with a stopTimer()/startTimer() pair. If
// timer_enabled == 0 timer is enabled
@@ -174,37 +179,45 @@ handle_tick(int unused STG_UNUSED)
void
initTimer(void)
{
+#if defined(HAVE_PREEMPTION)
initProfTimer();
if (RtsFlags.MiscFlags.tickInterval != 0) {
initTicker(RtsFlags.MiscFlags.tickInterval, handle_tick);
}
SEQ_CST_STORE(&timer_disabled, 1);
+#endif
}
void
startTimer(void)
{
+#if defined(HAVE_PREEMPTION)
if (atomic_dec(&timer_disabled) == 0) {
if (RtsFlags.MiscFlags.tickInterval != 0) {
startTicker();
}
}
+#endif
}
void
stopTimer(void)
{
+#if defined(HAVE_PREEMPTION)
if (atomic_inc(&timer_disabled, 1) == 1) {
if (RtsFlags.MiscFlags.tickInterval != 0) {
stopTicker();
}
}
+#endif
}
void
exitTimer (bool wait)
{
+#if defined(HAVE_PREEMPTION)
if (RtsFlags.MiscFlags.tickInterval != 0) {
exitTicker(wait);
}
+#endif
}