Work stealing for sparks
[ghc-hetmet.git] / includes / RtsTypes.h
1 /*
2   Time-stamp: <2005-03-30 12:02:33 simonmar>
3
4   RTS specific types.
5 */
6
7 /* -------------------------------------------------------------------------
8    Generally useful typedefs
9    ------------------------------------------------------------------------- */
10
11 #ifndef RTS_TYPES_H
12 #define RTS_TYPES_H
13
14 typedef unsigned int  nat;           /* at least 32 bits (like int) */
15 typedef unsigned long lnat;          /* at least 32 bits            */
16 #ifndef _MSC_VER
17 typedef unsigned long long ullong;   /* at least 32 bits            */
18 typedef long long llong;
19 #else
20 typedef unsigned __int64   ullong;   /* at least 32 bits            */
21 typedef __int64 llong;
22 #endif
23
24 /* ullong (64|128-bit) type: only include if needed (not ANSI) */
25 #if defined(__GNUC__) 
26 #define LL(x) (x##LL)
27 #else
28 #define LL(x) (x##L)
29 #endif
30   
31 typedef enum { 
32     rtsFalse = 0, 
33     rtsTrue 
34 } rtsBool;
35
36 /* 
37    Types specific to the parallel runtime system.
38 */
39
40
41 /* Spark pools: used to store pending sparks 
42  *  (THREADED_RTS & PARALLEL_HASKELL only)
43  * Implementation uses a DeQue to enable concurrent read accesses at
44  * the top end.
45  */
46 typedef struct  SparkPool_ {
47   /* Size of elements array. Used for modulo calculation: we round up
48      to powers of 2 and use the dyadic log (modulo == bitwise &) */
49   StgWord size; 
50   StgWord moduloSize; /* bitmask for modulo */
51
52   /* top, index where multiple readers steal() (protected by a cas) */
53   StgWord top;
54
55   /* bottom, index of next free place where one writer can push
56      elements. This happens unsynchronised. */
57   StgWord bottom;
58   /* both position indices are continuously incremented, and used as
59      an index modulo the current array size. */
60   
61   /* lower bound on the current top value. This is an internal
62      optimisation to avoid unnecessarily accessing the top field
63      inside pushBottom */
64   StgWord topBound;
65
66   /* The elements array */
67   StgClosurePtr* elements;
68   /*  Please note: the dataspace cannot follow the admin fields
69       immediately, as it should be possible to enlarge it without
70       disposing the old one automatically (as realloc would)! */
71
72 } SparkPool;
73
74 typedef ullong        rtsTime;
75
76 #if defined(PAR)
77 /* types only needed in the parallel system */
78 typedef struct hashtable ParHashTable;
79 typedef struct hashlist ParHashList;
80
81 /* typedef double REAL_TIME; */
82 /* typedef W_ TIME; */
83 /* typedef GlobalTaskId Proc; */
84 typedef int           GlobalTaskId;
85 typedef GlobalTaskId  PEs;
86 typedef unsigned int  rtsWeight;
87 typedef int           rtsPacket;
88 typedef int           OpCode;
89
90 /* Global addresses i.e. unique ids in a parallel setup; needed in Closures.h*/
91 typedef struct {
92   union {
93     StgPtr plc;
94     struct {
95       GlobalTaskId gtid;
96       int slot;
97     } gc;
98   } payload;
99   rtsWeight weight;
100 } globalAddr;
101
102 /* (GA, LA) pairs */
103 typedef struct gala {
104     globalAddr ga;
105     StgPtr la;
106     struct gala *next;
107     rtsBool preferred;
108 } GALA;
109
110 #elif defined(GRAN)
111
112 /*
113  * GlobalTaskId is dummy in GranSim;
114  * we define it to have cleaner code in the RTS
115  */
116 typedef int       GlobalTaskId;
117 typedef lnat      rtsTime;
118 typedef StgWord   PEs;
119
120 #endif
121
122 #endif /* RTS_TYPES_H */