-int
-initialize_virtual_timer(nat ms)
-{
- /* On Win32 setups that don't have support for
- setitimer(), we use the MultiMedia API's timer
- support.
-
- The delivery of ticks isn't free; the performance hit should be checked.
- */
- unsigned int delay;
- static unsigned int vtalrm_id = 0;
- static unsigned int period = -1;
-
- /* A zero argument value means shutdown. */
- if (ms != 0) {
- TIMECAPS tc;
-
- if ( timeGetDevCaps(&tc, sizeof(TIMECAPS)) == TIMERR_NOERROR) {
- period = tc.wPeriodMin;
- delay = timeBeginPeriod(period);
- if (delay == TIMERR_NOCANDO) { /* error of some sort. */
- return -1;
- }
- } else {
- return -1;
- }
-
- vtalrm_id =
- timeSetEvent(ms, /* event every `delay' milliseconds. */
- 1, /* precision is within 1 ms */
- vtalrm_cback,
- TIME_CALLBACK_FUNCTION, /* ordinary callback */
- TIME_PERIODIC);
- } else {
- /* Shutdown the MM timer */
- if ( vtalrm_id != 0 ) {
- timeKillEvent(vtalrm_id);
- }
- if (period > 0) {
- timeEndPeriod(period);
- }
- }