summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDuncan Coutts <duncan@well-typed.com>2020-12-28 22:15:06 +0000
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-01-25 05:11:14 -0500
commit4ad726fc1a5d062e2df2910d7f39ab81428dddfc (patch)
tree93adbaf8d20c8baa142c8cbb79d4c2c167b64925
parente93384e82fb4de5a5ee96949b7c1108bce16a875 (diff)
downloadhaskell-4ad726fc1a5d062e2df2910d7f39ab81428dddfc.tar.gz
Move hooks for I/O manager startup / shutdown into IOManager.{c,h}
-rw-r--r--rts/IOManager.c67
-rw-r--r--rts/IOManager.h18
-rw-r--r--rts/RtsStartup.c23
3 files changed, 88 insertions, 20 deletions
diff --git a/rts/IOManager.c b/rts/IOManager.c
index 03811f1daa..eaa1fe8cb6 100644
--- a/rts/IOManager.c
+++ b/rts/IOManager.c
@@ -20,6 +20,73 @@
#include "IOManager.h" // RTS internal
#include "Capability.h"
+#if defined(mingw32_HOST_OS) && !defined(THREADED_RTS)
+#include "win32/AsyncMIO.h"
+#include "win32/AsyncWinIO.h"
+#endif
+
+
+/* Called in the RTS initialisation
+ */
+void
+initIOManager(void)
+{
+
+#if defined(THREADED_RTS)
+ /* Posix implementation in posix/Signals.c
+ * Win32 implementation in win32/ThrIOManager.c
+ */
+ ioManagerStart();
+
+#elif defined(mingw32_HOST_OS)
+ /* Non-threaded Win32 implementation, either the WinIO IOCP implementation,
+ * or the classic implementation. */
+ if (is_io_mng_native_p()) {
+ startupAsyncWinIO();
+ } else {
+ startupAsyncIO();
+ }
+
+#else
+ /* The other implementation is the non-threaded Posix select() one.
+ * It does not need any initialisation.
+ */
+#endif
+
+}
+
+
+/* Called in the RTS shutdown before the scheduler exits
+ */
+void
+stopIOManager(void)
+{
+
+#if defined(THREADED_RTS)
+ /* Posix implementation in posix/Signals.c
+ * Win32 implementation in win32/ThrIOManager.c
+ */
+ ioManagerDie();
+#endif
+
+}
+
+
+/* Called in the RTS shutdown after the scheduler exits
+ */
+void
+exitIOManager(bool wait_threads USED_IF_NOT_THREADS_AND_MINGW32)
+{
+
+#if !defined(THREADED_RTS) && defined(mingw32_HOST_OS)
+ if (is_io_mng_native_p()) {
+ shutdownAsyncWinIO(wait_threads);
+ } else {
+ shutdownAsyncIO(wait_threads);
+ }
+#endif
+
+}
/* Declared in rts/IOInterface.h. Used only by the MIO threaded I/O manager on
* Unix platforms.
diff --git a/rts/IOManager.h b/rts/IOManager.h
index 713049305f..be9bc3ab1a 100644
--- a/rts/IOManager.h
+++ b/rts/IOManager.h
@@ -21,6 +21,16 @@
#include "BeginPrivate.h"
+/* Init hook: called from hs_init_ghc.
+ */
+void initIOManager(void);
+
+
+/* Shutdown hooks: called from hs_exit_ before and after the scheduler exits.
+ */
+void stopIOManager(void);
+void exitIOManager(bool wait_threads);
+
/*
* Communicating with the IO manager thread (see GHC.Conc).
* Posix implementation in posix/Signals.c
@@ -34,4 +44,12 @@ void ioManagerDie (void);
void ioManagerStart (void);
#endif
+/* Pedantic warning cleanliness
+ */
+#if !defined(THREADED_RTS) && defined(mingw32_HOST_OS)
+#define USED_IF_NOT_THREADS_AND_MINGW32
+#else
+#define USED_IF_NOT_THREADS_AND_MINGW32 STG_UNUSED
+#endif
+
#include "EndPrivate.h"
diff --git a/rts/RtsStartup.c b/rts/RtsStartup.c
index 7916ad61c8..818fbaa346 100644
--- a/rts/RtsStartup.c
+++ b/rts/RtsStartup.c
@@ -383,22 +383,12 @@ hs_init_ghc(int *argc, char **argv[], RtsConfig rts_config)
}
#endif
-#if defined(mingw32_HOST_OS) && !defined(THREADED_RTS)
- if (is_io_mng_native_p())
- startupAsyncWinIO();
- else
- startupAsyncIO();
-#endif
+ initIOManager();
x86_init_fpu();
startupHpc();
- // ditto.
-#if defined(THREADED_RTS)
- ioManagerStart();
-#endif
-
/* Record initialization times */
stat_endInit();
}
@@ -455,9 +445,7 @@ hs_exit_(bool wait_foreign)
checkFPUStack();
#endif
-#if defined(THREADED_RTS)
- ioManagerDie();
-#endif
+ stopIOManager();
/* stop all running tasks. This is also where we stop concurrent non-moving
* collection if it's running */
@@ -577,12 +565,7 @@ hs_exit_(bool wait_foreign)
if (tf != NULL) fclose(tf);
#endif
-#if defined(mingw32_HOST_OS) && !defined(THREADED_RTS)
- if (is_io_mng_native_p())
- shutdownAsyncWinIO(wait_foreign);
- else
- shutdownAsyncIO(wait_foreign);
-#endif
+ exitIOManager(wait_foreign);
/* Restore the console Codepage. */
#if defined(mingw32_HOST_OS)