13 * Provide a timer service for the RTS, periodically
14 * notifying it that a number of 'ticks' has passed.
18 /* To signal shutdown of the timer service, we use a local
19 * event which the timer thread listens to (and stopVirtTimer()
22 static HANDLE hStopEvent = INVALID_HANDLE_VALUE;
24 static TickProc tickProc = NULL;
27 * Ticking is done by a separate thread which periodically
28 * wakes up to handle a tick.
30 * This is the portable way of providing a timer service under
31 * Win32; features like waitable timers or timer queues are only
32 * supported by a subset of the Win32 platforms (notably not
39 TimerProc(PVOID param)
44 /* interpret a < 0 timeout period as 'instantaneous' */
48 waitRes = WaitForSingleObject(hStopEvent, ms);
52 /* event has become signalled */
54 CloseHandle(hStopEvent);
61 DWORD dw = GetLastError();
62 fprintf(stderr, "TimerProc: wait failed -- error code: %lu\n", dw); fflush(stderr);
66 fprintf(stderr, "TimerProc: unexpected result %lu\n", waitRes); fflush(stderr);
75 startTicker(nat ms, TickProc handle_tick)
78 /* 'hStopEvent' is a manual-reset event that's signalled upon
79 * shutdown of timer service (=> timer thread.)
81 hStopEvent = CreateEvent ( NULL,
85 if (hStopEvent == INVALID_HANDLE_VALUE) {
88 tickProc = handle_tick;
89 return ( 0 != _beginthreadex(NULL,
100 if (hStopEvent != INVALID_HANDLE_VALUE) {
101 SetEvent(hStopEvent);