Commit b88636e4 authored by sof's avatar sof

[project @ 2001-11-21 20:55:10 by sof]

initialize_virtual_timer: Robustified win32 version; don't
assume that the minimal resolution is one millisec, consult
the underlying impl via timeGetDevCaps().
parent b79fdec2
/* -----------------------------------------------------------------------------
* $Id: Itimer.c,v 1.24 2001/11/13 13:38:02 simonmar Exp $
* $Id: Itimer.c,v 1.25 2001/11/21 20:55:10 sof Exp $
*
* (c) The GHC Team, 1995-1999
*
......@@ -99,7 +99,7 @@ handle_tick(int unused STG_UNUSED)
LPTIMECALLBACK vtalrm_cback;
nat
int
initialize_virtual_timer(nat ms)
{
/* On Win32 setups that don't have support for
......@@ -109,13 +109,23 @@ initialize_virtual_timer(nat ms)
The delivery of ticks isn't free; the performance hit should be checked.
*/
unsigned int delay;
static unsigned int vtalrm_id;
static unsigned int vtalrm_id = 0;
static unsigned int period = -1;
if (ms) {
delay = timeBeginPeriod(1);
if (delay == TIMERR_NOCANDO) { /* error of some sort. */
return delay;
/* 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 */
......@@ -123,8 +133,13 @@ initialize_virtual_timer(nat ms)
TIME_CALLBACK_FUNCTION, /* ordinary callback */
TIME_PERIODIC);
} else {
timeKillEvent(vtalrm_id);
timeEndPeriod(1);
/* Shutdown the MM timer */
if ( vtalrm_id != 0 ) {
timeKillEvent(vtalrm_id);
}
if (period > 0) {
timeEndPeriod(period);
}
}
return 0;
......@@ -132,7 +147,7 @@ initialize_virtual_timer(nat ms)
#else
nat
int
initialize_virtual_timer(nat ms)
{
# ifndef HAVE_SETITIMER
......@@ -150,11 +165,11 @@ initialize_virtual_timer(nat ms)
# endif
}
#endif /* !cygwin32_TARGET_OS */
#endif /* !{mingw,cygwin32}_TARGET_OS */
# if 0
/* This is a potential POSIX version */
nat
int
initialize_virtual_timer(nat ms)
{
struct sigevent se;
......@@ -172,7 +187,7 @@ initialize_virtual_timer(nat ms)
it.it_value.tv_sec = ms / 1000;
it.it_value.tv_nsec = 1000000 * (ms - 1000 * it.it_value.tv_sec);
it.it_interval = it.it_value;
timer_settime(tid, TIMER_RELTIME, &it, NULL);
return timer_settime(tid, TIMER_RELTIME, &it, NULL);
}
# endif
......
/* -----------------------------------------------------------------------------
* $Id: Itimer.h,v 1.7 2000/08/25 13:12:07 simonmar Exp $
* $Id: Itimer.h,v 1.8 2001/11/21 20:55:10 sof Exp $
*
* (c) The GHC Team 1998-1999
*
......@@ -20,7 +20,7 @@ extern rtsBool do_prof_ticks; /* profiling ticks on/off */
/* Total number of ticks since startup */
extern lnat total_ticks;
nat initialize_virtual_timer ( nat ms );
int initialize_virtual_timer ( nat ms );
int install_vtalrm_handler ( void );
void block_vtalrm_signal ( void );
void unblock_vtalrm_signal ( void );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment