[project @ 1999-11-02 15:05:38 by simonmar]
[ghc-hetmet.git] / ghc / includes / SchedAPI.h
1 /* -----------------------------------------------------------------------------
2  * $Id: SchedAPI.h,v 1.7 1999/11/02 15:05:52 simonmar 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  * schedule() plus the thread creation functions are not part
16  * part of the external RTS API, so leave them out if we're
17  * not compiling rts/ bits.   -- sof 7/99
18  * 
19  */
20 SchedulerStatus waitThread(StgTSO *main_thread, /*out*/StgClosure **ret);
21
22 /* 
23  * Creating threads
24  */
25
26 StgTSO *createThread(nat stack_size);
27 void scheduleThread(StgTSO *tso);
28
29 static inline void pushClosure   (StgTSO *tso, StgClosure *c) {
30   tso->sp--;
31   tso->sp[0] = (W_) c;
32 }
33
34 static inline void pushRealWorld (StgTSO *tso) {
35   tso->sp--;
36   tso->sp[0] = (W_) REALWORLD_TAG;
37 }
38 static inline StgTSO *
39 createGenThread(nat stack_size,  StgClosure *closure) {
40   StgTSO *t;
41   t = createThread(stack_size);
42   pushClosure(t,closure);
43   return t;
44 }
45
46 static inline StgTSO *
47 createIOThread(nat stack_size,  StgClosure *closure) {
48   StgTSO *t;
49   t = createThread(stack_size);
50   pushRealWorld(t);
51   pushClosure(t,closure);
52   return t;
53 }
54
55 /*
56  * Same as above, but also evaluate the result of the IO action
57  * to whnf while we're at it.
58  */
59
60 static inline StgTSO *
61 createStrictIOThread(nat stack_size,  StgClosure *closure) {
62   StgTSO *t;
63   t = createThread(stack_size);
64   pushClosure(t,closure);
65   pushClosure(t,(StgClosure*)&forceIO_closure);
66   return t;
67 }
68
69
70 /* 
71  * Killing threads
72  */
73
74 void    deleteThread(StgTSO *tso);
75
76 /*
77  * Reverting CAFs
78  */
79
80 void RevertCAFs(void);
81
82 #endif