[project @ 1999-03-02 19:44:07 by sof]
[ghc-hetmet.git] / ghc / includes / TSO.h
1 /* -----------------------------------------------------------------------------
2  * $Id: TSO.h,v 1.5 1999/03/02 19:44:22 sof Exp $
3  *
4  * (c) The GHC Team, 1998-1999
5  *
6  * The definitions for Thread State Objects.
7  *
8  * ---------------------------------------------------------------------------*/
9
10 #ifndef TSO_H
11 #define TSO_H
12
13 #if defined(PROFILING)
14 typedef struct {
15   CostCentreStack *CCCS;        /* thread's current CCS */
16 } StgTSOProfInfo;
17 #else /* !PROFILING */
18 typedef struct {
19 } StgTSOProfInfo;
20 #endif /* PROFILING */
21
22 #if defined(PAR)
23 typedef struct {
24 } StgTSOParInfo;
25 #else /* !PAR */
26 typedef struct {
27 } StgTSOParInfo;
28 #endif /* PAR */
29
30 #if defined(TICKY)
31 typedef struct {
32 } StgTSOTickyInfo;
33 #else /* !TICKY */
34 typedef struct {
35 } StgTSOTickyInfo;
36 #endif /* TICKY */
37
38 typedef enum {
39     tso_state_runnable,
40     tso_state_stopped
41 } StgTSOState;
42
43 typedef enum {
44   ThreadEnterGHC,
45   ThreadRunGHC,
46   ThreadEnterHugs,
47   ThreadKilled,
48   ThreadComplete
49 } StgTSOWhatNext;
50
51 /*
52  * We are completely paranoid and make thread IDs 64 bits to avoid
53  * having to worry about overflow.  A little calculation shows that
54  * even doing 10^6 forks per second would take 35 million years to
55  * overflow a 64 bit thread ID :-)
56  *
57  */
58 typedef StgWord32 StgThreadID;
59
60 /*
61  * This type is returned to the scheduler by a thread that has
62  * stopped for one reason or another.
63  */
64
65 typedef enum {
66   HeapOverflow,                 /* might also be StackOverflow */
67   StackOverflow,
68   ThreadYielding,
69   ThreadBlocked,
70   ThreadFinished
71 } StgThreadReturnCode;
72
73 /*
74  * TSOs live on the heap, and therefore look just like heap objects.
75  * Large TSOs will live in their own "block group" allocated by the
76  * storage manager, and won't be copied during garbage collection.
77  */
78
79 typedef struct StgTSO_ {
80   StgHeader          header;
81   struct StgTSO_*    link;
82   StgMutClosure *    mut_link;  /* TSO's are mutable of course! */
83   StgTSOWhatNext     whatNext;
84   StgTSOState        state;     /* necessary? */
85   StgThreadID        id;
86   /* Exception Handlers */
87   StgTSOTickyInfo    ticky; 
88   StgTSOProfInfo     prof;
89   StgTSOParInfo      par;
90   /* GranSim Info? */
91
92   /* The thread stack... */
93   StgWord            stack_size;     /* stack size in *words* */
94   StgWord            max_stack_size; /* maximum stack size in *words* */
95   StgPtr             sp;
96   StgUpdateFrame*    su;
97   StgPtr             splim;
98   
99   StgWord            stack[0];
100 } StgTSO;
101
102 extern DLL_IMPORT_RTS StgTSO      *CurrentTSO;
103
104
105 /* Workaround for a bug/quirk in gcc on certain architectures.
106  * symptom is that (&tso->stack - &tso->header) /=  sizeof(StgTSO)
107  * in other words, gcc pads the structure at the end.
108  */
109
110 extern StgTSO dummy_tso;
111
112 #define TSO_STRUCT_SIZE \
113    ((int)&(dummy_tso).stack - (int)&(dummy_tso).header)
114
115 #define TSO_STRUCT_SIZEW (TSO_STRUCT_SIZE / sizeof(W_))
116
117 #endif /* TSO_H */