26dac54e7610635881fd2a48c2cbe90ed74dc6b3
[ghc-hetmet.git] / ghc / includes / SchedAPI.h
1 /* -----------------------------------------------------------------------------
2  * $Id: SchedAPI.h,v 1.3 1999/05/21 14:46:21 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 SchedulerStatus schedule(StgTSO *main_thread, /*out*/StgClosure **ret);
27
28 /* 
29  * Creating threads
30  */
31
32 StgTSO *createThread   (nat stack_size);
33
34 static inline void pushClosure   (StgTSO *tso, StgClosure *c) {
35   tso->sp--;
36   tso->sp[0] = (W_) c;
37 }
38
39 static inline void pushRealWorld (StgTSO *tso) {
40   tso->sp--;
41   tso->sp[0] = (W_) REALWORLD_TAG;
42 }
43 static inline StgTSO *
44 createGenThread(nat stack_size,  StgClosure *closure) {
45   StgTSO *t;
46   t = createThread(stack_size);
47   pushClosure(t,closure);
48   return t;
49 }
50
51 static inline StgTSO *
52 createIOThread(nat stack_size,  StgClosure *closure) {
53   StgTSO *t;
54   t = createThread(stack_size);
55   pushRealWorld(t);
56   pushClosure(t,closure);
57   return t;
58 }
59
60 /*
61  * Same as above, but also evaluate the result of the IO action
62  * to whnf while we're at it.
63  */
64
65 static inline StgTSO *
66 createStrictIOThread(nat stack_size,  StgClosure *closure) {
67   StgTSO *t;
68   t = createThread(stack_size);
69   pushClosure(t,closure);
70   pushClosure(t,&forceIO_closure);
71   return t;
72 }
73
74
75 /* 
76  * Killing threads
77  */
78
79 void    deleteThread(StgTSO *tso);
80
81 /*
82  * Reverting CAFs
83  */
84
85 void RevertCAFs(void);
86
87 #endif