*/
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.
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;
}
}
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.)
*/
if (hStopEvent == INVALID_HANDLE_VALUE) {
return 0;
}
+ tickProc = handle_tick;
return ( 0 != _beginthreadex(NULL,
0,
TimerProc,
(LPVOID)ms,
0,
- NULL) );
+ &threadId) );
}
int