Fixes for console event handling on Win32 in the threaded/SMP runtime.
(it now builds, but is untested).
#else /* PAR */
#define signals_pending() (rtsFalse)
-#define handleSignalsInThisThread() /* nothing */
#endif /* PAR */
#include "Capability.h"
#include "Task.h"
#include "AwaitEvent.h"
+#if defined(mingw32_HOST_OS)
+#include "win32/IOManager.h"
+#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#if defined(SMP)
static void schedulePushWork(Capability *cap, Task *task);
#endif
-static void scheduleStartSignalHandlers (void);
+static void scheduleStartSignalHandlers (Capability *cap);
static void scheduleCheckBlockedThreads (Capability *cap);
static void scheduleCheckBlackHoles (Capability *cap);
static void scheduleDetectDeadlock (Capability *cap, Task *task);
}
#endif // SMP
- scheduleStartSignalHandlers();
+ scheduleStartSignalHandlers(cap);
// Only check the black holes here if we've nothing else to do.
// During normal execution, the black hole list only gets checked
* ------------------------------------------------------------------------- */
static void
-scheduleStartSignalHandlers(void)
+scheduleStartSignalHandlers(Capability *cap)
{
-#if defined(RTS_USER_SIGNALS) && !defined(THREADED_RTS)
+#if defined(RTS_USER_SIGNALS) && (!defined(THREADED_RTS) || defined(mingw32_HOST_OS))
if (signals_pending()) { // safe outside the lock
- startSignalHandlers();
+ startSignalHandlers(cap);
}
#endif
}
if ( !emptyRunQueue(cap) ) return;
-#if defined(RTS_USER_SIGNALS) && !defined(THREADED_RTS)
+#if defined(RTS_USER_SIGNALS) && (!defined(THREADED_RTS) || defined(mingw32_HOST_OS))
/* If we have user-installed signal handlers, then wait
* for signals to arrive rather then bombing out with a
* deadlock.
awaitUserSignals();
if (signals_pending()) {
- startSignalHandlers();
+ startSignalHandlers(cap);
}
// either we have threads to run, or we were interrupted:
{
blockUserSignals();
- ASSERT_LOCK_HELD(&sched_mutex);
-
while (next_pending_handler != pending_handler_buf) {
next_pending_handler--;
+#if !defined(THREADED_RTS) /* to the end */
/*
* Wait/check for external events. Periodically, the
* Scheduler checks for the completion of external operations,
&& emptyRunQueue(&MainCapability)
);
}
+#endif
* Run the handlers associated with the stacked up console events. Console
* event delivery is blocked for the duration of this call.
*/
-void startSignalHandlers(void)
+void startSignalHandlers(Capability *cap)
{
StgStablePtr handler;
if (console_handler < 0) {
return;
}
+
blockUserSignals();
+ ACQUIRE_LOCK(&sched_mutex);
handler = deRefStablePtr((StgStablePtr)console_handler);
while (stg_pending_events > 0) {
stg_pending_events--;
- scheduleThread(&MainCapability,
- createIOThread(&MainCapability,
+ scheduleThread(cap,
+ createIOThread(cap,
RtsFlags.GcFlags.initialStkSize,
- rts_apply(&MainCapability,
+ rts_apply(cap,
(StgClosure *)handler,
- rts_mkInt(&MainCapability,
+ rts_mkInt(cap,
stg_pending_buf[stg_pending_events]))));
}
+
+ RELEASE_LOCK(&sched_mutex);
unblockUserSignals();
}
-
/*
* Function: markSignalHandlers()
*
}
-/*
- * Function: handleSignalsInThisThread()
- *
- * Have current (OS) thread assume responsibility of handling console events/signals.
- * Currently not used (by the console event handling code.)
- */
-void handleSignalsInThisThread(void)
-{
- return;
-}
-
/*
* Function: generic_handler()
*
*/
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:
resetAbandonRequestWait();
return TRUE;
}
+
+ RELEASE_LOCK(&sched_mutex);
}
* Run the handlers associated with the queued up console events. Console
* event delivery is blocked for the duration of this call.
*/
-extern void startSignalHandlers(void);
+extern void startSignalHandlers(Capability *cap);
/*
* Function: handleSignalsInThisThread()