summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Marlow <simonmar@microsoft.com>2007-12-04 15:39:18 +0000
committerSimon Marlow <simonmar@microsoft.com>2007-12-04 15:39:18 +0000
commitdffddba53a656bf59f2463edc845ca1af9fa133e (patch)
treed0db08f14a1a85ed257829b9d8e2f326e3ec6292
parent87e82c15b1ab2eb3dd37c681f6615ec47b476f9f (diff)
downloadhaskell-dffddba53a656bf59f2463edc845ca1af9fa133e.tar.gz
protect console handler against concurrent access (#1922)
-rw-r--r--rts/win32/ConsoleHandler.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/rts/win32/ConsoleHandler.c b/rts/win32/ConsoleHandler.c
index a2de74b54a..76ebea0583 100644
--- a/rts/win32/ConsoleHandler.c
+++ b/rts/win32/ConsoleHandler.c
@@ -264,8 +264,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 +280,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;
}
}