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