fix the build with GHC 6.4 (not 6.4.1)
[ghc-hetmet.git] / ghc / rts / win32 / Ticker.c
index bfc89c0..c1390b7 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,14 +50,20 @@ 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;
+    case WAIT_FAILED: {
+       DWORD dw = GetLastError();
+       fprintf(stderr, "TimerProc: wait failed -- error code: %lu\n", dw); fflush(stderr);
+       break; 
+    }
     default:
-      fprintf(stderr, "timer: unexpected result %lu\n", waitRes); fflush(stderr);
+      fprintf(stderr, "TimerProc: unexpected result %lu\n", waitRes); fflush(stderr);
       break;
     }
   }
@@ -64,9 +72,9 @@ 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
    * shutdown of timer service (=> timer thread.)
    */
@@ -77,12 +85,13 @@ startTicker(nat ms)
   if (hStopEvent == INVALID_HANDLE_VALUE) {
     return 0;
   }
+  tickProc = handle_tick;
   return ( 0 != _beginthreadex(NULL,
                               0,
                               TimerProc,
                               (LPVOID)ms,
                               0,
-                              NULL) );
+                              &threadId) );
 }
 
 int