X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=rts%2Fwin32%2FConsoleHandler.c;h=19057a3d8d5c3e1d855aeb12cd1c4dce16c49044;hb=653e325e08c5f632aa194f9239e938faca5abba5;hp=308b77bfcca410beb175833cb88952a7af3fdf79;hpb=610de7d17e09318272b7516bd9b97e8b2cbd170c;p=ghc-hetmet.git diff --git a/rts/win32/ConsoleHandler.c b/rts/win32/ConsoleHandler.c index 308b77b..19057a3 100644 --- a/rts/win32/ConsoleHandler.c +++ b/rts/win32/ConsoleHandler.c @@ -5,10 +5,8 @@ #include "Rts.h" #include #include "ConsoleHandler.h" -#include "SchedAPI.h" #include "Schedule.h" #include "RtsUtils.h" -#include "RtsFlags.h" #include "AsyncIO.h" #include "RtsSignals.h" @@ -18,7 +16,9 @@ static BOOL WINAPI shutdown_handler(DWORD dwCtrlType); static BOOL WINAPI generic_handler(DWORD dwCtrlType); static rtsBool deliver_event = rtsTrue; -static StgInt console_handler = STG_SIG_DFL; +StgInt console_handler = STG_SIG_DFL; + +#if !defined(THREADED_RTS) static HANDLE hConsoleEvent = INVALID_HANDLE_VALUE; @@ -26,6 +26,8 @@ static HANDLE hConsoleEvent = INVALID_HANDLE_VALUE; StgInt stg_pending_events = 0; /* number of undelivered events */ DWORD stg_pending_buf[N_PENDING_EVENTS]; /* their associated event numbers. */ +#endif + /* * Function: initUserSignals() * @@ -34,8 +36,9 @@ DWORD stg_pending_buf[N_PENDING_EVENTS]; /* their associated event numbers. */ void initUserSignals(void) { - stg_pending_events = 0; console_handler = STG_SIG_DFL; +#if !defined (THREADED_RTS) + stg_pending_events = 0; if (hConsoleEvent == INVALID_HANDLE_VALUE) { hConsoleEvent = CreateEvent ( NULL, /* default security attributes */ @@ -43,15 +46,24 @@ initUserSignals(void) FALSE, /* initially non-signalled */ NULL); /* no name */ } +#endif return; } void +freeSignalHandlers(void) { + /* Do nothing */ +} + +/* Seems to be a bit of an orphan...where used? */ +void finiUserSignals(void) { +#if !defined (THREADED_RTS) if (hConsoleEvent != INVALID_HANDLE_VALUE) { CloseHandle(hConsoleEvent); } +#endif } /* @@ -82,9 +94,6 @@ static BOOL WINAPI shutdown_handler(DWORD dwCtrlType) stg_exit(EXIT_INTERRUPTED); } else { interruptStgRts(); - /* Cheesy pulsing of an event to wake up a waiting RTS thread, if any */ - abandonRequestWait(); - resetAbandonRequestWait(); } return TRUE; @@ -108,6 +117,12 @@ void initDefaultHandlers(void) } } +void resetDefaultHandlers(void) +{ + if ( !SetConsoleCtrlHandler(shutdown_handler, FALSE) ) { + errorBelch("warning: failed to uninstall default console handler"); + } +} /* * Function: blockUserSignals() @@ -147,6 +162,7 @@ void awaitUserSignals(void) } +#if !defined (THREADED_RTS) /* * Function: startSignalHandlers() * @@ -179,6 +195,7 @@ void startSignalHandlers(Capability *cap) RELEASE_LOCK(&sched_mutex); unblockUserSignals(); } +#endif /* !THREADED_RTS */ /* * Function: markSignalHandlers() @@ -186,7 +203,7 @@ void startSignalHandlers(Capability *cap) * Evacuate the handler stack. _Assumes_ that console event delivery * has already been blocked. */ -void markSignalHandlers (evac_fn evac) +void markSignalHandlers (evac_fn evac STG_UNUSED, void *user STG_UNUSED) { // nothing to mark; the console handler is a StablePtr which is // already treated as a root by the GC. @@ -201,8 +218,6 @@ void markSignalHandlers (evac_fn evac) */ static BOOL WINAPI generic_handler(DWORD dwCtrlType) { - ACQUIRE_LOCK(&sched_mutex); - /* Ultra-simple -- up the counter + signal a switch. */ switch(dwCtrlType) { case CTRL_CLOSE_EVENT: @@ -216,17 +231,19 @@ static BOOL WINAPI generic_handler(DWORD dwCtrlType) default: if (!deliver_event) return TRUE; +#if defined(THREADED_RTS) + sendIOManagerEvent((StgWord8) ((dwCtrlType<<1) | 1)); +#else if ( stg_pending_events < N_PENDING_EVENTS ) { stg_pending_buf[stg_pending_events] = dwCtrlType; stg_pending_events++; } - /* Cheesy pulsing of an event to wake up a waiting RTS thread, if any */ - abandonRequestWait(); - resetAbandonRequestWait(); + + // we need to wake up awaitEvent() + abandonRequestWait(); +#endif return TRUE; } - - RELEASE_LOCK(&sched_mutex); } @@ -254,8 +271,13 @@ rts_InstallConsoleEvent(int action, StgStablePtr *handler) } break; case STG_SIG_HAN: +#ifdef THREADED_RTS + // handler is stored in an MVar in the threaded RTS + console_handler = STG_SIG_HAN; +#else console_handler = (StgInt)*handler; - if ( previous_hdlr < 0 ) { +#endif + if (previous_hdlr < 0 || previous_hdlr == STG_SIG_HAN) { /* Only install generic_handler() once */ if ( !SetConsoleCtrlHandler(generic_handler, TRUE) ) { errorBelch("warning: unable to install console event handler"); @@ -265,10 +287,13 @@ rts_InstallConsoleEvent(int action, StgStablePtr *handler) } if (previous_hdlr == STG_SIG_DFL || - previous_hdlr == STG_SIG_IGN) { + previous_hdlr == STG_SIG_IGN || + previous_hdlr == STG_SIG_HAN) { return previous_hdlr; } else { - *handler = (StgStablePtr)previous_hdlr; + if (handler != NULL) { + *handler = (StgStablePtr)previous_hdlr; + } return STG_SIG_HAN; } } @@ -292,17 +317,22 @@ rts_InstallConsoleEvent(int action, StgStablePtr *handler) * */ void -rts_ConsoleHandlerDone(int ev) +rts_ConsoleHandlerDone (int ev USED_IF_NOT_THREADS) { +#if !defined(THREADED_RTS) if ( (DWORD)ev == CTRL_BREAK_EVENT || (DWORD)ev == CTRL_C_EVENT ) { /* only these two cause stdin system calls to abort.. */ SetEvent(hConsoleEvent); /* event is manual-reset */ Sleep(0); /* yield */ ResetEvent(hConsoleEvent); /* turn it back off again */ + // SDM: yeuch, this can't possibly work reliably. + // I'm not having it in THREADED_RTS. } +#endif } +#if !defined(THREADED_RTS) /* * Function: rts_waitConsoleHandlerCompletion() * @@ -317,3 +347,4 @@ rts_waitConsoleHandlerCompletion() */ return (WaitForSingleObject(hConsoleEvent, INFINITE) == WAIT_OBJECT_0); } +#endif