[project @ 1999-02-05 16:02:18 by simonm]
[ghc-hetmet.git] / ghc / includes / TSO.h
1 /* -----------------------------------------------------------------------------
2  * $Id: TSO.h,v 1.4 1999/02/05 16:02:30 simonm 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 typedef StgNat32 StgThreadID;
58
59 /*
60  * This type is returned to the scheduler by a thread that has
61  * stopped for one reason or another.
62  */
63
64 typedef enum {
65   HeapOverflow,                 /* might also be StackOverflow */
66   StackOverflow,
67   ThreadYielding,
68   ThreadBlocked,
69   ThreadFinished
70 } StgThreadReturnCode;
71
72 /*
73  * TSOs live on the heap, and therefore look just like heap objects.
74  * Large TSOs will live in their own "block group" allocated by the
75  * storage manager, and won't be copied during garbage collection.
76  */
77
78 typedef struct StgTSO_ {
79   StgHeader          header;
80   struct StgTSO_*    link;
81   StgMutClosure *    mut_link;  /* TSO's are mutable of course! */
82   StgTSOWhatNext     whatNext;
83   StgTSOState        state;     /* necessary? */
84   StgThreadID        id;
85   /* Exception Handlers */
86   StgTSOTickyInfo    ticky; 
87   StgTSOProfInfo     prof;
88   StgTSOParInfo      par;
89   /* GranSim Info? */
90
91   /* The thread stack... */
92   StgWord            stack_size;     /* stack size in *words* */
93   StgWord            max_stack_size; /* maximum stack size in *words* */
94   StgPtr             sp;
95   StgUpdateFrame*    su;
96   StgPtr             splim;
97   
98   StgWord            stack[0];
99 } StgTSO;
100
101 extern StgTSO      *CurrentTSO;
102
103
104 /* Workaround for a bug/quirk in gcc on certain architectures.
105  * symptom is that (&tso->stack - &tso->header) /=  sizeof(StgTSO)
106  * in other words, gcc pads the structure at the end.
107  */
108
109 extern StgTSO dummy_tso;
110
111 #define TSO_STRUCT_SIZE \
112    ((int)&(dummy_tso).stack - (int)&(dummy_tso).header)
113
114 #define TSO_STRUCT_SIZEW (TSO_STRUCT_SIZE / sizeof(W_))
115
116 #endif /* TSO_H */