[project @ 1999-07-03 18:39:40 by sof]
[ghc-hetmet.git] / ghc / includes / SchedAPI.h
1 /* -----------------------------------------------------------------------------
2  * $Id: SchedAPI.h,v 1.5 1999/07/03 18:39:41 sof Exp $
3  *
4  * (c) The GHC Team 1998
5  *
6  * External API for the scheduler.  For most uses, the functions in
7  * RtsAPI.h should be enough.
8  *
9  * ---------------------------------------------------------------------------*/
10
11 #ifndef SCHEDAPI_H
12 #define SCHEDAPI_H
13
14 /*
15  * Running the scheduler
16  */
17
18 typedef enum {
19     Success,      
20     Killed,      /* another thread killed us                           */
21     Interrupted, /* stopped in response to a call to interruptStgRts   */
22     Deadlock,   
23     AllBlocked,  /* subtly different from Deadlock                     */
24 } SchedulerStatus;
25       
26
27 /* 
28  * schedule() plus the thread creation functions are not part
29  * part of the external RTS API, so leave them out if we're
30  * not compiling rts/ bits.   -- sof 7/99
31  * 
32  */
33 #ifdef COMPILING_RTS
34
35 SchedulerStatus schedule(StgTSO *main_thread, /*out*/StgClosure **ret);
36
37 /* 
38  * Creating threads
39  */
40
41 StgTSO *createThread   (nat stack_size);
42
43 static inline void pushClosure   (StgTSO *tso, StgClosure *c) {
44   tso->sp--;
45   tso->sp[0] = (W_) c;
46 }
47
48 static inline void pushRealWorld (StgTSO *tso) {
49   tso->sp--;
50   tso->sp[0] = (W_) REALWORLD_TAG;
51 }
52 static inline StgTSO *
53 createGenThread(nat stack_size,  StgClosure *closure) {
54   StgTSO *t;
55   t = createThread(stack_size);
56   pushClosure(t,closure);
57   return t;
58 }
59
60 static inline StgTSO *
61 createIOThread(nat stack_size,  StgClosure *closure) {
62   StgTSO *t;
63   t = createThread(stack_size);
64   pushRealWorld(t);
65   pushClosure(t,closure);
66   return t;
67 }
68
69 /*
70  * Same as above, but also evaluate the result of the IO action
71  * to whnf while we're at it.
72  */
73
74 static inline StgTSO *
75 createStrictIOThread(nat stack_size,  StgClosure *closure) {
76   StgTSO *t;
77   t = createThread(stack_size);
78   pushClosure(t,closure);
79   pushClosure(t,(StgClosure*)&forceIO_closure);
80   return t;
81 }
82
83
84 /* 
85  * Killing threads
86  */
87
88 void    deleteThread(StgTSO *tso);
89
90 /*
91  * Reverting CAFs
92  */
93
94 void RevertCAFs(void);
95 #endif
96
97 #endif