18c48f5f9cf6c5c8155593d12cdacbfcf00947a1
[ghc-hetmet.git] / ghc / includes / SchedAPI.h
1 /* -----------------------------------------------------------------------------
2  * $Id: SchedAPI.h,v 1.9 2000/01/13 14:34:01 hwloidl 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 #if defined(GRAN)
15 // Dummy def for NO_PRI if not in GranSim
16 #define NO_PRI  0
17 #endif
18
19 /* 
20  * schedule() plus the thread creation functions are not part
21  * part of the external RTS API, so leave them out if we're
22  * not compiling rts/ bits.   -- sof 7/99
23  * 
24  */
25 SchedulerStatus waitThread(StgTSO *main_thread, /*out*/StgClosure **ret);
26
27 /* 
28  * Creating threads
29  */
30 #if defined(GRAN)
31 StgTSO *createThread(nat stack_size, StgInt pri);
32 #else
33 StgTSO *createThread(nat stack_size);
34 #endif
35 void scheduleThread(StgTSO *tso);
36
37 static inline void pushClosure   (StgTSO *tso, StgClosure *c) {
38   tso->sp--;
39   tso->sp[0] = (W_) c;
40 }
41
42 static inline void pushRealWorld (StgTSO *tso) {
43   tso->sp--;
44   tso->sp[0] = (W_) REALWORLD_TAG;
45 }
46 static inline StgTSO *
47 createGenThread(nat stack_size,  StgClosure *closure) {
48   StgTSO *t;
49 #if defined(GRAN)
50   t = createThread(stack_size, NO_PRI);
51 #else
52   t = createThread(stack_size);
53 #endif
54   pushClosure(t,closure);
55   return t;
56 }
57
58 static inline StgTSO *
59 createIOThread(nat stack_size,  StgClosure *closure) {
60   StgTSO *t;
61 #if defined(GRAN)
62   t = createThread(stack_size, NO_PRI);
63 #else
64   t = createThread(stack_size);
65 #endif
66   pushRealWorld(t);
67   pushClosure(t,closure);
68   return t;
69 }
70
71 /*
72  * Same as above, but also evaluate the result of the IO action
73  * to whnf while we're at it.
74  */
75
76 static inline StgTSO *
77 createStrictIOThread(nat stack_size,  StgClosure *closure) {
78   StgTSO *t;
79 #if defined(GRAN)
80   t = createThread(stack_size, NO_PRI);
81 #else
82   t = createThread(stack_size);
83 #endif
84   pushClosure(t,closure);
85   pushClosure(t,(StgClosure*)&forceIO_closure);
86   return t;
87 }
88
89
90 /* 
91  * Killing threads
92  */
93
94 void    deleteThread(StgTSO *tso);
95 void    deleteAllThreads ( void );
96
97 /*
98  * Reverting CAFs
99  */
100
101 void RevertCAFs(void);
102
103 #endif