EventLog: Factor out ensureRoomFor*Event
[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 StgTSO* raiseAsync (Capability *cap,
23 StgTSO *tso,
24 StgClosure *exception,
25 rtsBool stop_at_atomically,
26 StgUpdateFrame *stop_here);
27
28 void throwToSingleThreaded (Capability *cap,
29 StgTSO *tso,
30 StgClosure *exception);
31
32 void throwToSingleThreaded_ (Capability *cap,
33 StgTSO *tso,
34 StgClosure *exception,
35 rtsBool stop_at_atomically);
36
37 void throwToSelf (Capability *cap,
38 StgTSO *tso,
39 StgClosure *exception);
40
41 void suspendComputation (Capability *cap,
42 StgTSO *tso,
43 StgUpdateFrame *stop_here);
44
45 MessageThrowTo *throwTo (Capability *cap, // the Capability we hold
46 StgTSO *source,
47 StgTSO *target,
48 StgClosure *exception); // the exception closure
49
50 nat throwToMsg (Capability *cap,
51 MessageThrowTo *msg);
52
53 int maybePerformBlockedException (Capability *cap, StgTSO *tso);
54 void awakenBlockedExceptionQueue (Capability *cap, StgTSO *tso);
55
56 /* Determine whether a thread is interruptible (ie. blocked
57 * indefinitely). Interruptible threads can be sent an exception with
58 * killThread# even if they have async exceptions blocked.
59 */
60 INLINE_HEADER int
61 interruptible(StgTSO *t)
62 {
63 switch (t->why_blocked) {
64 case BlockedOnMVar:
65 case BlockedOnSTM:
66 case BlockedOnMVarRead:
67 case BlockedOnMsgThrowTo:
68 case BlockedOnRead:
69 case BlockedOnWrite:
70 #if defined(mingw32_HOST_OS)
71 case BlockedOnDoProc:
72 #endif
73 case BlockedOnDelay:
74 return 1;
75 // NB. Threaded blocked on foreign calls (BlockedOnCCall) are
76 // *not* interruptible. We can't send these threads an exception.
77 default:
78 return 0;
79 }
80 }
81
82 #include "EndPrivate.h"
83
84 #endif /* CMINUSMINUS */
85
86 #endif /* RAISEASYNC_H */