summaryrefslogtreecommitdiff
path: root/rts/RaiseAsync.h
diff options
context:
space:
mode:
authorSimon Marlow <simonmar@microsoft.com>2006-06-16 10:33:42 +0000
committerSimon Marlow <simonmar@microsoft.com>2006-06-16 10:33:42 +0000
commitb1953bbb1ed3cb16497e5447db7487f0c2d9e41a (patch)
treedf9e129c57b586a952634dc080939b621ae64cf8 /rts/RaiseAsync.h
parent1e3d53b4707a6c9c7c99cdaa54e3646b840f5cc9 (diff)
downloadhaskell-b1953bbb1ed3cb16497e5447db7487f0c2d9e41a.tar.gz
Asynchronous exception support for SMP
This patch makes throwTo work with -threaded, and also refactors large parts of the concurrency support in the RTS to clean things up. We have some new files: RaiseAsync.{c,h} asynchronous exception support Threads.{c,h} general threading-related utils Some of the contents of these new files used to be in Schedule.c, which is smaller and cleaner as a result of the split. Asynchronous exception support in the presence of multiple running Haskell threads is rather tricky. In fact, to my annoyance there are still one or two bugs to track down, but the majority of the tests run now.
Diffstat (limited to 'rts/RaiseAsync.h')
-rw-r--r--rts/RaiseAsync.h71
1 files changed, 71 insertions, 0 deletions
diff --git a/rts/RaiseAsync.h b/rts/RaiseAsync.h
new file mode 100644
index 0000000000..8e59d51d9f
--- /dev/null
+++ b/rts/RaiseAsync.h
@@ -0,0 +1,71 @@
+/* ---------------------------------------------------------------------------
+ *
+ * (c) The GHC Team, 1998-2006
+ *
+ * Asynchronous exceptions
+ *
+ * --------------------------------------------------------------------------*/
+
+#ifndef RAISEASYNC_H
+#define RAISEASYNC_H
+
+#define THROWTO_SUCCESS 0
+#define THROWTO_BLOCKED 1
+
+#ifndef CMINUSMINUS
+void throwToSingleThreaded (Capability *cap,
+ StgTSO *tso,
+ StgClosure *exception);
+
+void throwToSingleThreaded_ (Capability *cap,
+ StgTSO *tso,
+ StgClosure *exception,
+ rtsBool stop_at_atomically,
+ StgPtr stop_here);
+
+void suspendComputation (Capability *cap,
+ StgTSO *tso,
+ StgPtr stop_here);
+
+nat throwTo (Capability *cap, // the Capability we hold
+ StgTSO *source, // the TSO sending the exception
+ StgTSO *target, // the TSO receiving the exception
+ StgClosure *exception, // the exception closure
+ /*[out]*/ void **out // pass to throwToReleaseTarget()
+ );
+
+#ifdef THREADED_RTS
+void throwToReleaseTarget (void *tso);
+#endif
+
+void maybePerformBlockedException (Capability *cap, StgTSO *tso);
+void awakenBlockedExceptionQueue (Capability *cap, StgTSO *tso);
+
+/* Determine whether a thread is interruptible (ie. blocked
+ * indefinitely). Interruptible threads can be sent an exception with
+ * killThread# even if they have async exceptions blocked.
+ */
+STATIC_INLINE int
+interruptible(StgTSO *t)
+{
+ switch (t->why_blocked) {
+ case BlockedOnMVar:
+ case BlockedOnException:
+ case BlockedOnRead:
+ case BlockedOnWrite:
+#if defined(mingw32_HOST_OS)
+ case BlockedOnDoProc:
+#endif
+ case BlockedOnDelay:
+ return 1;
+ // NB. Threaded blocked on foreign calls (BlockedOnCCall) are
+ // *not* interruptible. We can't send these threads an exception.
+ default:
+ return 0;
+ }
+}
+
+#endif /* CMINUSMINUS */
+
+#endif /* RAISEASYNC_H */
+