[project @ 2003-03-29 00:27:11 by sof]
authorsof <unknown>
Sat, 29 Mar 2003 00:27:11 +0000 (00:27 +0000)
committersof <unknown>
Sat, 29 Mar 2003 00:27:11 +0000 (00:27 +0000)
startTicker(): pass in the tick handler as an arg

ghc/rts/Itimer.c
ghc/rts/Itimer.h
ghc/rts/Timer.c
ghc/rts/Timer.h
ghc/rts/win32/Ticker.c
ghc/rts/win32/Ticker.h

index 4c94232..74801db 100644 (file)
@@ -1,5 +1,5 @@
 /* -----------------------------------------------------------------------------
- * $Id: Itimer.c,v 1.34 2003/03/29 00:00:41 sof Exp $
+ * $Id: Itimer.c,v 1.35 2003/03/29 00:27:11 sof Exp $
  *
  * (c) The GHC Team, 1995-1999
  *
@@ -42,7 +42,7 @@
 
 static
 int
-install_vtalrm_handler(void)
+install_vtalrm_handler(TickProc handle_tick)
 {
     struct sigaction action;
 
@@ -55,7 +55,7 @@ install_vtalrm_handler(void)
 }
 
 int
-startTicker(nat ms)
+startTicker(nat ms, TickProc handle_tick)
 {
 # ifndef HAVE_SETITIMER
   /*    fprintf(stderr, "No virtual timer on this system\n"); */
@@ -63,7 +63,7 @@ startTicker(nat ms)
 # else
     struct itimerval it;
 
-    install_vtalrm_handler();
+    install_vtalrm_handler(handle_tick);
 
     timestamp = getourtimeofday();
 
index e473ad5..adfe12a 100644 (file)
@@ -1,5 +1,5 @@
 /* -----------------------------------------------------------------------------
- * $Id: Itimer.h,v 1.12 2003/03/28 23:46:40 sof Exp $
+ * $Id: Itimer.h,v 1.13 2003/03/29 00:27:11 sof Exp $
  *
  * (c) The GHC Team 1998-2001
  *
@@ -9,7 +9,7 @@
 #ifndef __ITIMER_H__
 #define __ITIMER_H__
 
-extern int startTicker( nat ms );
+extern int startTicker( nat ms, TickProc handle_tick);
 extern int stopTicker ( void );
 
 extern unsigned int getourtimeofday   ( void );
index 5425116..013fd06 100644 (file)
@@ -35,6 +35,7 @@ static int ticks_to_ctxt_switch = 0;
  * At each occurrence of a tick, the OS timer will invoke
  * handle_tick().
  */
+static
 void
 handle_tick(int unused STG_UNUSED)
 {
@@ -57,7 +58,7 @@ startTimer(nat ms)
   initProfTimer();
 #endif
 
-  return startTicker(ms);
+  return startTicker(ms, handle_tick);
 }
 
 int
index e13570f..1c4696e 100644 (file)
@@ -16,7 +16,8 @@
  */
 #define CS_MIN_MILLISECS TICK_MILLISECS       /* milliseconds per slice */
 
-extern void handle_tick(int unused);
+typedef void (*TickProc)(int);
+
 extern int startTimer(nat ms);
 extern int stopTimer(void);
 #endif /* __TIMER_H__ */
index 194ec8d..124cbc8 100644 (file)
@@ -21,6 +21,8 @@
  */
 static HANDLE hStopEvent = INVALID_HANDLE_VALUE;
 
+static TickProc tickProc = NULL;
+
 /*
  * Ticking is done by a separate thread which periodically
  * wakes up to handle a tick.
@@ -48,11 +50,12 @@ TimerProc(PVOID param)
     switch (waitRes) {
     case WAIT_OBJECT_0:
       /* event has become signalled */
+      tickProc = NULL;
       CloseHandle(hStopEvent);
       return 0;
     case WAIT_TIMEOUT:
       /* tick */
-      handle_tick(0);
+      tickProc(0);
       break;
     default:
       fprintf(stderr, "timer: unexpected result %lu\n", waitRes); fflush(stderr);
@@ -64,7 +67,7 @@ TimerProc(PVOID param)
 
 
 int
-startTicker(nat ms)
+startTicker(nat ms, TickProc handle_tick)
 {
   unsigned threadId;
   /* 'hStopEvent' is a manual-reset event that's signalled upon
@@ -77,6 +80,7 @@ startTicker(nat ms)
   if (hStopEvent == INVALID_HANDLE_VALUE) {
     return 0;
   }
+  tickProc = handle_tick;
   return ( 0 != _beginthreadex(NULL,
                               0,
                               TimerProc,
index 669a0a1..6104f93 100644 (file)
@@ -3,7 +3,7 @@
  */
 #ifndef __TICKER_H__
 #define __TICKER_H__
-extern int  startTicker( nat ms );
+extern int  startTicker( nat ms, TickProc handle_tick );
 extern int  stopTicker ( void );
 #endif /* __TICKER_H__ */