1 /* -----------------------------------------------------------------------------
3 * (c) The GHC Team, 1995-2003
5 * Interval timer service for profiling and pre-emptive scheduling.
7 * ---------------------------------------------------------------------------*/
10 * The interval timer is used for profiling and for context switching in the
13 * This file defines the platform-independent view of interval timing, relying
14 * on platform-specific services to install and run the timers.
19 #include "Proftimer.h"
22 #include "Capability.h"
24 #if !defined(mingw32_HOST_OS)
27 #include "win32/Ticker.h"
30 /* ticks left before next pre-emptive context switch */
31 static int ticks_to_ctxt_switch = 0;
34 * Function: handle_tick()
36 * At each occurrence of a tick, the OS timer will invoke
41 handle_tick(int unused STG_UNUSED)
46 if (RtsFlags.ConcFlags.ctxtSwitchTicks > 0) {
47 ticks_to_ctxt_switch--;
48 if (ticks_to_ctxt_switch <= 0) {
49 ticks_to_ctxt_switch = RtsFlags.ConcFlags.ctxtSwitchTicks;
50 context_switch = 1; /* schedule a context switch */
52 #if defined(RTS_SUPPORTS_THREADS)
54 * If we've been inactive for a whole time slice, tell the
55 * scheduler to wake up and do a GC, to check for threads
56 * that are deadlocked.
58 switch (recent_activity) {
60 recent_activity = ACTIVITY_MAYBE_NO;
62 case ACTIVITY_MAYBE_NO:
63 recent_activity = ACTIVITY_INACTIVE;
64 blackholes_need_checking = rtsTrue;
65 /* hack: re-use the blackholes_need_checking flag */
67 /* ToDo: this threadRunnable only works if there's
68 * another thread (not this one) waiting to be woken up
86 return startTicker(ms, handle_tick);