+#ifdef HAVE_SIGNAL_H
+# include <signal.h>
+#endif
+
+static lnat total_ticks = 0;
+
+/* ticks left before next pre-emptive context switch */
+static int ticks_to_ctxt_switch = 0;
+
+/* -----------------------------------------------------------------------------
+ Tick handler
+
+ We use the ticker for time profiling.
+
+ SMP note: this signal could be delivered to *any* thread. We have
+ to ensure that it doesn't matter which thread actually runs the
+ signal handler.
+ -------------------------------------------------------------------------- */
+
+static
+void
+#if defined(mingw32_TARGET_OS) || (defined(cygwin32_TARGET_OS) && !defined(HAVE_SETITIMER))
+
+CALLBACK
+handle_tick(UINT uID STG_UNUSED, UINT uMsg STG_UNUSED, DWORD dwUser STG_UNUSED,
+ DWORD dw1 STG_UNUSED, DWORD d STG_UNUSED)
+#else
+handle_tick(int unused STG_UNUSED)
+#endif
+{
+ total_ticks++;
+
+#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 */
+ }
+ }
+}
+
+