/* -----------------------------------------------------------------------------
- * $Id: Itimer.c,v 1.34 2003/03/29 00:00:41 sof Exp $
+ * $Id: Itimer.c,v 1.35 2003/03/29 00:27:11 sof Exp $
*
* (c) The GHC Team, 1995-1999
*
static
int
-install_vtalrm_handler(void)
+install_vtalrm_handler(TickProc handle_tick)
{
struct sigaction action;
}
int
-startTicker(nat ms)
+startTicker(nat ms, TickProc handle_tick)
{
# ifndef HAVE_SETITIMER
/* fprintf(stderr, "No virtual timer on this system\n"); */
# else
struct itimerval it;
- install_vtalrm_handler();
+ install_vtalrm_handler(handle_tick);
timestamp = getourtimeofday();
/* -----------------------------------------------------------------------------
- * $Id: Itimer.h,v 1.12 2003/03/28 23:46:40 sof Exp $
+ * $Id: Itimer.h,v 1.13 2003/03/29 00:27:11 sof Exp $
*
* (c) The GHC Team 1998-2001
*
#ifndef __ITIMER_H__
#define __ITIMER_H__
-extern int startTicker( nat ms );
+extern int startTicker( nat ms, TickProc handle_tick);
extern int stopTicker ( void );
extern unsigned int getourtimeofday ( void );
* At each occurrence of a tick, the OS timer will invoke
* handle_tick().
*/
+static
void
handle_tick(int unused STG_UNUSED)
{
initProfTimer();
#endif
- return startTicker(ms);
+ return startTicker(ms, handle_tick);
}
int
*/
#define CS_MIN_MILLISECS TICK_MILLISECS /* milliseconds per slice */
-extern void handle_tick(int unused);
+typedef void (*TickProc)(int);
+
extern int startTimer(nat ms);
extern int stopTimer(void);
#endif /* __TIMER_H__ */
*/
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;
default:
fprintf(stderr, "timer: unexpected result %lu\n", waitRes); fflush(stderr);
int
-startTicker(nat ms)
+startTicker(nat ms, TickProc handle_tick)
{
unsigned threadId;
/* 'hStopEvent' is a manual-reset event that's signalled upon
if (hStopEvent == INVALID_HANDLE_VALUE) {
return 0;
}
+ tickProc = handle_tick;
return ( 0 != _beginthreadex(NULL,
0,
TimerProc,
*/
#ifndef __TICKER_H__
#define __TICKER_H__
-extern int startTicker( nat ms );
+extern int startTicker( nat ms, TickProc handle_tick );
extern int stopTicker ( void );
#endif /* __TICKER_H__ */