X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=rts%2Fwin32%2FConsoleHandler.c;h=19057a3d8d5c3e1d855aeb12cd1c4dce16c49044;hb=653e325e08c5f632aa194f9239e938faca5abba5;hp=a2de74b54a2f9d606cad7e01de65bf15bb8592e5;hpb=ed12b7043fa98928f75c289a756fbcef546315f8;p=ghc-hetmet.git diff --git a/rts/win32/ConsoleHandler.c b/rts/win32/ConsoleHandler.c index a2de74b..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" @@ -119,6 +117,12 @@ void initDefaultHandlers(void) } } +void resetDefaultHandlers(void) +{ + if ( !SetConsoleCtrlHandler(shutdown_handler, FALSE) ) { + errorBelch("warning: failed to uninstall default console handler"); + } +} /* * Function: blockUserSignals() @@ -199,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 STG_UNUSED) +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. @@ -234,6 +238,9 @@ static BOOL WINAPI generic_handler(DWORD dwCtrlType) stg_pending_buf[stg_pending_events] = dwCtrlType; stg_pending_events++; } + + // we need to wake up awaitEvent() + abandonRequestWait(); #endif return TRUE; } @@ -264,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"); @@ -275,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; } }