Fold ghc-prim.git into ghc.git (re #8545)
[ghc.git] / rts / RaiseAsync.h
1 /* ---------------------------------------------------------------------------
2 *
3 * (c) The GHC Team, 1998-2006
4 *
5 * Asynchronous exceptions
6 *
7 * --------------------------------------------------------------------------*/
8
9 #ifndef RAISEASYNC_H
10 #define RAISEASYNC_H
11
12 #define THROWTO_SUCCESS 0
13 #define THROWTO_BLOCKED 1
14
15 #ifndef CMINUSMINUS
16
17 #include "BeginPrivate.h"
18
19 void blockedThrowTo (Capability *cap,
20 StgTSO *target, MessageThrowTo *msg);
21
22 void throwToSingleThreaded (Capability *cap,
23 StgTSO *tso,
24 StgClosure *exception);
25
26 void throwToSingleThreaded_ (Capability *cap,
27 StgTSO *tso,
28 StgClosure *exception,
29 rtsBool stop_at_atomically);
30
31 void suspendComputation (Capability *cap,
32 StgTSO *tso,
33 StgUpdateFrame *stop_here);
34
35 MessageThrowTo *throwTo (Capability *cap, // the Capability we hold
36 StgTSO *source,
37 StgTSO *target,
38 StgClosure *exception); // the exception closure
39
40 nat throwToMsg (Capability *cap,
41 MessageThrowTo *msg);
42
43 int maybePerformBlockedException (Capability *cap, StgTSO *tso);
44 void awakenBlockedExceptionQueue (Capability *cap, StgTSO *tso);
45
46 /* Determine whether a thread is interruptible (ie. blocked
47 * indefinitely). Interruptible threads can be sent an exception with
48 * killThread# even if they have async exceptions blocked.
49 */
50 INLINE_HEADER int
51 interruptible(StgTSO *t)
52 {
53 switch (t->why_blocked) {
54 case BlockedOnMVar:
55 case BlockedOnMVarRead:
56 case BlockedOnMsgThrowTo:
57 case BlockedOnRead:
58 case BlockedOnWrite:
59 #if defined(mingw32_HOST_OS)
60 case BlockedOnDoProc:
61 #endif
62 case BlockedOnDelay:
63 return 1;
64 // NB. Threaded blocked on foreign calls (BlockedOnCCall) are
65 // *not* interruptible. We can't send these threads an exception.
66 default:
67 return 0;
68 }
69 }
70
71 #include "EndPrivate.h"
72
73 #endif /* CMINUSMINUS */
74
75 #endif /* RAISEASYNC_H */
76