[project @ 2003-02-22 04:51:50 by sof]
[ghc-hetmet.git] / ghc / rts / Timer.c
diff --git a/ghc/rts/Timer.c b/ghc/rts/Timer.c
new file mode 100644 (file)
index 0000000..1f9db85
--- /dev/null
@@ -0,0 +1,67 @@
+/* -----------------------------------------------------------------------------
+ *
+ * (c) The GHC Team, 1995-2003
+ *
+ * Interval timer service for profiling and pre-emptive scheduling.
+ *
+ * ---------------------------------------------------------------------------*/
+
+/*
+ * The interval timer is used for profiling and for context switching in the
+ * threaded build. 
+ *
+ * This file defines the platform-independent view of interval timing, relying
+ * on platform-specific services to install and run the timers.
+ *
+ */
+#include "Rts.h"
+#include "RtsFlags.h"
+#include "Proftimer.h"
+#include "Schedule.h"
+#include "Timer.h"
+
+#ifndef mingw32_TARGET_OS
+#include "Itimer.h"
+#else
+#include "win32/Ticker.h"
+#endif
+
+/* ticks left before next pre-emptive context switch */
+static int ticks_to_ctxt_switch = 0;
+
+/*
+ * Function: handle_tick()
+ *
+ * At each occurrence of a tick, the OS timer will invoke
+ * handle_tick().
+ */
+void
+handle_tick(int unused STG_UNUSED)
+{
+#ifdef PROFILING
+  handleProfTick();
+#endif
+  if (RtsFlags.ConcFlags.ctxtSwitchTicks > 0) {
+      ticks_to_ctxt_switch--;
+      if (ticks_to_ctxt_switch <= 0) {
+         ticks_to_ctxt_switch = RtsFlags.ConcFlags.ctxtSwitchTicks;
+         context_switch = 1;   /* schedule a context switch */
+      }
+  }
+}
+
+int
+startTimer(nat ms)
+{
+#ifdef PROFILING
+  initProfTimer();
+#endif
+
+  return startTicker(ms);
+}
+
+int
+stopTimer()
+{
+  return stopTicker();
+}