summaryrefslogtreecommitdiff
path: root/rts
diff options
context:
space:
mode:
authorDylan Yudaken <dylany@fb.com>2020-10-06 13:42:22 +0100
committerMarge Bot <ben+marge-bot@smart-cactus.org>2020-10-17 22:02:50 -0400
commit50e9df49b7cd637c4552ab34bf629a01af4767c0 (patch)
tree15576b62a40dbb4bbf6ca58bc6afab6e4ff9e732 /rts
parent451455fd008500259f5d2207bdfdccf6dddb52c5 (diff)
downloadhaskell-50e9df49b7cd637c4552ab34bf629a01af4767c0.tar.gz
When using rts_setInCallCapability, lock incall threads
This diff makes sure that incall threads, when using `rts_setInCallCapability`, will be created as locked. If the thread is not locked, the thread might end up being scheduled to a different capability. While this is mentioned in the docs for `rts_setInCallCapability,`, it makes the method significantly less useful as there is no guarantees on the capability being used. This commit also adds a test to make sure things stay on the correct capability.
Diffstat (limited to 'rts')
-rw-r--r--rts/RtsAPI.c20
-rw-r--r--rts/RtsSymbols.c1
2 files changed, 21 insertions, 0 deletions
diff --git a/rts/RtsAPI.c b/rts/RtsAPI.c
index 51a1f2b7cf..1d8e0bc1c8 100644
--- a/rts/RtsAPI.c
+++ b/rts/RtsAPI.c
@@ -461,6 +461,26 @@ void rts_evalIO (/* inout */ Capability **cap,
}
/*
+ * rts_inCall() is similar to rts_evalIO, but expects to be called as an incall,
+ * and is not expected to be called by user code directly.
+ */
+void rts_inCall (/* inout */ Capability **cap,
+ /* in */ HaskellObj p,
+ /* out */ HaskellObj *ret)
+{
+ StgTSO* tso;
+
+ tso = createStrictIOThread(*cap, RtsFlags.GcFlags.initialStkSize, p);
+ if ((*cap)->running_task->preferred_capability != -1) {
+ // enabled_capabilities should not change between here and waitCapability()
+ ASSERT((*cap)->no == ((*cap)->running_task->preferred_capability % enabled_capabilities));
+ // we requested explicit affinity; don't move this thread from now on.
+ tso->flags |= TSO_LOCKED;
+ }
+ scheduleWaitThread(tso,ret,cap);
+}
+
+/*
* rts_evalStableIOMain() is suitable for calling main Haskell thread
* stored in (StablePtr (IO a)) it calls rts_evalStableIO but wraps
* function in GHC.TopHandler.runMainIO that installs top_handlers.
diff --git a/rts/RtsSymbols.c b/rts/RtsSymbols.c
index 9b8a4ae16d..e433d9d369 100644
--- a/rts/RtsSymbols.c
+++ b/rts/RtsSymbols.c
@@ -763,6 +763,7 @@
SymI_HasProto(rts_evalStableIOMain) \
SymI_HasProto(rts_evalStableIO) \
SymI_HasProto(rts_eval_) \
+ SymI_HasProto(rts_inCall) \
SymI_HasProto(rts_getBool) \
SymI_HasProto(rts_getChar) \
SymI_HasProto(rts_getDouble) \