[project @ 2003-02-22 04:51:50 by sof]
[ghc-hetmet.git] / ghc / rts / Timer.c
1 /* -----------------------------------------------------------------------------
2  *
3  * (c) The GHC Team, 1995-2003
4  *
5  * Interval timer service for profiling and pre-emptive scheduling.
6  *
7  * ---------------------------------------------------------------------------*/
8
9 /*
10  * The interval timer is used for profiling and for context switching in the
11  * threaded build. 
12  *
13  * This file defines the platform-independent view of interval timing, relying
14  * on platform-specific services to install and run the timers.
15  *
16  */
17 #include "Rts.h"
18 #include "RtsFlags.h"
19 #include "Proftimer.h"
20 #include "Schedule.h"
21 #include "Timer.h"
22
23 #ifndef mingw32_TARGET_OS
24 #include "Itimer.h"
25 #else
26 #include "win32/Ticker.h"
27 #endif
28
29 /* ticks left before next pre-emptive context switch */
30 static int ticks_to_ctxt_switch = 0;
31
32 /*
33  * Function: handle_tick()
34  *
35  * At each occurrence of a tick, the OS timer will invoke
36  * handle_tick().
37  */
38 void
39 handle_tick(int unused STG_UNUSED)
40 {
41 #ifdef PROFILING
42   handleProfTick();
43 #endif
44   if (RtsFlags.ConcFlags.ctxtSwitchTicks > 0) {
45       ticks_to_ctxt_switch--;
46       if (ticks_to_ctxt_switch <= 0) {
47           ticks_to_ctxt_switch = RtsFlags.ConcFlags.ctxtSwitchTicks;
48           context_switch = 1;   /* schedule a context switch */
49       }
50   }
51 }
52
53 int
54 startTimer(nat ms)
55 {
56 #ifdef PROFILING
57   initProfTimer();
58 #endif
59
60   return startTicker(ms);
61 }
62
63 int
64 stopTimer()
65 {
66   return stopTicker();
67 }