rename StgSync to SpinLock
[ghc-hetmet.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 void throwToSingleThreaded (Capability *cap,
17                             StgTSO *tso,
18                             StgClosure *exception);
19
20 void throwToSingleThreaded_ (Capability *cap, 
21                              StgTSO *tso, 
22                              StgClosure *exception, 
23                              rtsBool stop_at_atomically,
24                              StgPtr stop_here);
25
26 void suspendComputation (Capability *cap, 
27                          StgTSO *tso, 
28                          StgPtr stop_here);
29
30 nat throwTo (Capability *cap,            // the Capability we hold 
31              StgTSO *source,             // the TSO sending the exception
32              StgTSO *target,             // the TSO receiving the exception
33              StgClosure *exception,      // the exception closure
34              /*[out]*/ void **out   // pass to throwToReleaseTarget()
35     );
36
37 #ifdef THREADED_RTS
38 void throwToReleaseTarget (void *tso);
39 #endif
40
41 int  maybePerformBlockedException (Capability *cap, StgTSO *tso);
42 void awakenBlockedExceptionQueue  (Capability *cap, StgTSO *tso);
43
44 /* Determine whether a thread is interruptible (ie. blocked
45  * indefinitely).  Interruptible threads can be sent an exception with
46  * killThread# even if they have async exceptions blocked.
47  */
48 INLINE_HEADER int
49 interruptible(StgTSO *t)
50 {
51   switch (t->why_blocked) {
52   case BlockedOnMVar:
53   case BlockedOnException:
54   case BlockedOnRead:
55   case BlockedOnWrite:
56 #if defined(mingw32_HOST_OS)
57   case BlockedOnDoProc:
58 #endif
59   case BlockedOnDelay:
60     return 1;
61   // NB. Threaded blocked on foreign calls (BlockedOnCCall) are
62   // *not* interruptible.  We can't send these threads an exception.
63   default:
64     return 0;
65   }
66 }
67
68 #endif /* CMINUSMINUS */
69
70 #endif /* RAISEASYNC_H */
71