Commit ff54eadf authored by sof's avatar sof

[project @ 2003-03-29 00:27:11 by sof]

startTicker(): pass in the tick handler as an arg
parent 47e6674f
/* -----------------------------------------------------------------------------
* $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
*
......@@ -42,7 +42,7 @@
static
int
install_vtalrm_handler(void)
install_vtalrm_handler(TickProc handle_tick)
{
struct sigaction action;
......@@ -55,7 +55,7 @@ install_vtalrm_handler(void)
}
int
startTicker(nat ms)
startTicker(nat ms, TickProc handle_tick)
{
# ifndef HAVE_SETITIMER
/* fprintf(stderr, "No virtual timer on this system\n"); */
......@@ -63,7 +63,7 @@ startTicker(nat ms)
# 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
*
......@@ -9,7 +9,7 @@
#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 );
......
......@@ -35,6 +35,7 @@ static int ticks_to_ctxt_switch = 0;
* At each occurrence of a tick, the OS timer will invoke
* handle_tick().
*/
static
void
handle_tick(int unused STG_UNUSED)
{
......@@ -57,7 +58,7 @@ startTimer(nat ms)
initProfTimer();
#endif
return startTicker(ms);
return startTicker(ms, handle_tick);
}
int
......
......@@ -16,7 +16,8 @@
*/
#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__ */
......@@ -21,6 +21,8 @@
*/
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.
......@@ -48,11 +50,12 @@ TimerProc(PVOID param)
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);
......@@ -64,7 +67,7 @@ TimerProc(PVOID param)
int
startTicker(nat ms)
startTicker(nat ms, TickProc handle_tick)
{
unsigned threadId;
/* 'hStopEvent' is a manual-reset event that's signalled upon
......@@ -77,6 +80,7 @@ startTicker(nat ms)
if (hStopEvent == INVALID_HANDLE_VALUE) {
return 0;
}
tickProc = handle_tick;
return ( 0 != _beginthreadex(NULL,
0,
TimerProc,
......
......@@ -3,7 +3,7 @@
*/
#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__ */
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