From 94a87d21ff345bbea0935bae19f8eb3f20feadb0 Mon Sep 17 00:00:00 2001
From: Duncan Coutts <duncan@well-typed.com>
Date: Wed, 11 Jan 2023 18:05:21 +0000
Subject: [PATCH] Add I/O manager API notifyIOManagerCapabilitiesChanged

Used in setNumCapabilities.

It only does anything for MIO on Posix.

Previously it always invoked Haskell code, but that code only did
anything on non-Windows (and non-JS), and only threaded. That currently
effectively means the MIO I/O manager on Posix.

So now it only invokes it for the MIO Posix case.
---
 rts/IOManager.c | 17 +++++++++++++++++
 rts/IOManager.h |  6 ++++++
 rts/Schedule.c  |  2 +-
 3 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/rts/IOManager.c b/rts/IOManager.c
index 0c0b1819fcc8..e6db47fa50fe 100644
--- a/rts/IOManager.c
+++ b/rts/IOManager.c
@@ -31,6 +31,7 @@
 
 #if defined(IOMGR_ENABLED_MIO_POSIX)
 #include "posix/Signals.h"
+#include "Prelude.h"
 #endif
 
 #if defined(IOMGR_ENABLED_MIO_WIN32)
@@ -362,6 +363,22 @@ initIOManagerAfterFork(Capability **pcap)
 }
 
 
+/* Called from setNumCapabilities.
+ */
+void notifyIOManagerCapabilitiesChanged(Capability **pcap)
+{
+    switch (iomgr_type) {
+#if defined(IOMGR_ENABLED_MIO_POSIX)
+        case IO_MANAGER_MIO_POSIX:
+            rts_evalIO(pcap, ioManagerCapabilitiesChanged_closure, NULL);
+            break;
+#endif
+        default:
+            break;
+    }
+}
+
+
 /* Called in the RTS shutdown before the scheduler exits
  */
 void
diff --git a/rts/IOManager.h b/rts/IOManager.h
index 7d9b793e31c6..24218e9315d0 100644
--- a/rts/IOManager.h
+++ b/rts/IOManager.h
@@ -226,6 +226,7 @@ void initCapabilityIOManager(CapIOManager **iomgr);
  */
 void initIOManager(void);
 
+
 /* Init hook: called from forkProcess in the child process on the surviving
  * capability.
  *
@@ -239,6 +240,11 @@ void initIOManagerAfterFork(/* inout */ Capability **pcap);
  */
 
 
+/* Called from setNumCapabilities.
+ */
+void notifyIOManagerCapabilitiesChanged(Capability **pcap);
+
+
 /* Shutdown hooks: called from hs_exit_ before and after the scheduler exits.
  *
  * The stopIOManager is also called many times (once per-capability) within the
diff --git a/rts/Schedule.c b/rts/Schedule.c
index 7aac5047b474..1dd903e27a99 100644
--- a/rts/Schedule.c
+++ b/rts/Schedule.c
@@ -2381,7 +2381,7 @@ setNumCapabilities (uint32_t new_n_capabilities USED_IF_THREADS)
     }
 
     // Notify IO manager that the number of capabilities has changed.
-    rts_evalIO(&cap, ioManagerCapabilitiesChanged_closure, NULL);
+    notifyIOManagerCapabilitiesChanged(&cap);
 
     startTimer();
 
-- 
GitLab