- waitRes = WaitForSingleObject(hStopEvent, ms);
-
- switch (waitRes) {
- case WAIT_OBJECT_0:
- /* event has become signalled */
- tickProc = NULL;
- CloseHandle(hStopEvent);
- return 0;
- case WAIT_TIMEOUT:
- /* tick */
- 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, "TimerProc: unexpected result %lu\n", waitRes); fflush(stderr);
- break;
- }
+ switch (ticker_state) {
+ case TickerGo:
+ waitRes = WaitForSingleObject(hStopEvent, ms);
+ break;
+ case TickerPause:
+ waitRes = WaitForSingleObject(hStopEvent, INFINITE);
+ break;
+ case TickerExit:
+ /* event has become signalled */
+ tickProc = NULL;
+ CloseHandle(hStopEvent);
+ hStopEvent = INVALID_HANDLE_VALUE;
+ return 0;
+ }
+
+ switch (waitRes) {
+ case WAIT_OBJECT_0:
+ /* event has become signalled */
+ ResetEvent(hStopEvent);
+ continue;
+ case WAIT_TIMEOUT:
+ /* tick */
+ tickProc(0);
+ break;
+ case WAIT_FAILED:
+ sysErrorBelch("TimerProc: WaitForSingleObject failed");
+ break;
+ default:
+ errorBelch("TimerProc: unexpected result %lu\n", waitRes);
+ break;
+ }