X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Frts%2Fwin32%2FTicker.c;h=c1390b7d7642bf4629c43086c6943f4c849f1ff2;hb=71f2cb608d5cf9ed86ecbd194c03dbc356a1c4e7;hp=bfc89c01f13b44985c63b3cb1c1c8649ecd4016e;hpb=557947d3f93e11285e36423ddb08d859af60ab47;p=ghc-hetmet.git diff --git a/ghc/rts/win32/Ticker.c b/ghc/rts/win32/Ticker.c index bfc89c0..c1390b7 100644 --- a/ghc/rts/win32/Ticker.c +++ b/ghc/rts/win32/Ticker.c @@ -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