From ff54eadfb873ca938ea16b3861e751cba499c34d Mon Sep 17 00:00:00 2001 From: sof Date: Sat, 29 Mar 2003 00:27:11 +0000 Subject: [PATCH] [project @ 2003-03-29 00:27:11 by sof] startTicker(): pass in the tick handler as an arg --- ghc/rts/Itimer.c | 8 ++++---- ghc/rts/Itimer.h | 4 ++-- ghc/rts/Timer.c | 3 ++- ghc/rts/Timer.h | 3 ++- ghc/rts/win32/Ticker.c | 8 ++++++-- ghc/rts/win32/Ticker.h | 2 +- 6 files changed, 17 insertions(+), 11 deletions(-) diff --git a/ghc/rts/Itimer.c b/ghc/rts/Itimer.c index 4c94232..74801db 100644 --- a/ghc/rts/Itimer.c +++ b/ghc/rts/Itimer.c @@ -1,5 +1,5 @@ /* ----------------------------------------------------------------------------- - * $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(); diff --git a/ghc/rts/Itimer.h b/ghc/rts/Itimer.h index e473ad5..adfe12a 100644 --- a/ghc/rts/Itimer.h +++ b/ghc/rts/Itimer.h @@ -1,5 +1,5 @@ /* ----------------------------------------------------------------------------- - * $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 ); diff --git a/ghc/rts/Timer.c b/ghc/rts/Timer.c index 5425116..013fd06 100644 --- a/ghc/rts/Timer.c +++ b/ghc/rts/Timer.c @@ -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 diff --git a/ghc/rts/Timer.h b/ghc/rts/Timer.h index e13570f..1c4696e 100644 --- a/ghc/rts/Timer.h +++ b/ghc/rts/Timer.h @@ -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__ */ diff --git a/ghc/rts/win32/Ticker.c b/ghc/rts/win32/Ticker.c index 194ec8d..124cbc8 100644 --- a/ghc/rts/win32/Ticker.c +++ b/ghc/rts/win32/Ticker.c @@ -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, diff --git a/ghc/rts/win32/Ticker.h b/ghc/rts/win32/Ticker.h index 669a0a1..6104f93 100644 --- a/ghc/rts/win32/Ticker.h +++ b/ghc/rts/win32/Ticker.h @@ -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__ */ -- 1.7.10.4