[project @ 2001-03-22 03:51:08 by hwloidl]
[ghc-hetmet.git] / ghc / includes / SchedAPI.h
1 /* -----------------------------------------------------------------------------
2  * $Id: SchedAPI.h,v 1.13 2001/03/22 03:51:09 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 #if defined(PAR) || defined(SMP)
36 void taskStart(void);
37 #endif
38 void scheduleThread(StgTSO *tso);
39
40 static inline void pushClosure   (StgTSO *tso, StgClosure *c) {
41   tso->sp--;
42   tso->sp[0] = (W_) c;
43 }
44
45 static inline void pushRealWorld (StgTSO *tso) {
46   tso->sp--;
47   tso->sp[0] = (W_) REALWORLD_TAG;
48 }
49 static inline StgTSO *
50 createGenThread(nat stack_size,  StgClosure *closure) {
51   StgTSO *t;
52 #if defined(GRAN)
53   t = createThread(stack_size, NO_PRI);
54 #else
55   t = createThread(stack_size);
56 #endif
57   pushClosure(t,closure);
58   return t;
59 }
60
61 static inline StgTSO *
62 createIOThread(nat stack_size,  StgClosure *closure) {
63   StgTSO *t;
64 #if defined(GRAN)
65   t = createThread(stack_size, NO_PRI);
66 #else
67   t = createThread(stack_size);
68 #endif
69   pushRealWorld(t);
70   pushClosure(t,closure);
71   return t;
72 }
73
74 /*
75  * Same as above, but also evaluate the result of the IO action
76  * to whnf while we're at it.
77  */
78
79 static inline StgTSO *
80 createStrictIOThread(nat stack_size,  StgClosure *closure) {
81   StgTSO *t;
82 #if defined(GRAN)
83   t = createThread(stack_size, NO_PRI);
84 #else
85   t = createThread(stack_size);
86 #endif
87   pushClosure(t,closure);
88   pushClosure(t,(StgClosure*)&stg_forceIO_closure);
89   return t;
90 }
91
92
93 /* 
94  * Killing threads
95  */
96 extern void deleteThread(StgTSO *tso);
97 extern void deleteAllThreads ( void );
98 extern int  howManyThreadsAvail ( void );
99 /*
100  * Run until there are no more threads.
101  */
102 extern void finishAllThreads ( void );
103
104 /*
105  * Reverting CAFs
106  */
107 extern void RevertCAFs ( void );
108
109 #endif