changes for handling unresolved in-var pointer.
[IRC.git] / Robust / src / Runtime / mlp_runtime.h
1 #ifndef __MLP_RUNTIME__
2 #define __MLP_RUNTIME__
3
4
5 #include <pthread.h>
6 #include "Queue.h"
7 #include "psemaphore.h"
8 #include "mlp_lock.h"
9
10 #ifndef FALSE
11 #define FALSE 0
12 #endif
13
14 #ifndef TRUE
15 #define TRUE 1
16 #endif
17
18 #define NUMBINS 64
19 #define NUMREAD 64
20 #define NUMITEMS 64
21 #define NUMRENTRY 256
22
23 #define READY 1
24 #define NOTREADY 0
25
26 #define READ 0
27 #define WRITE 1
28 #define PARENTREAD 2
29 #define PARENTWRITE 3
30 #define COARSE 4
31 #define PARENTCOARSE 5
32 #define SCCITEM 6
33
34 #define HASHTABLE 0
35 #define VECTOR 1
36 #define SINGLEITEM 2
37
38 #define READBIN 0
39 #define WRITEBIN 1
40
41 #define H_MASK (NUMBINS<<4)-1
42
43 #ifndef FALSE
44 #define FALSE 0
45 #endif
46
47 #ifndef TRUE
48 #define TRUE 1
49 #endif
50
51 typedef struct REntry_t{
52   int type; // fine read:0, fine write:1, parent read:2, parent write:3 coarse: 4, parent coarse:5, scc: 6
53   struct Hashtable_t* hashtable;
54   struct BinItem_t* binitem;
55   struct Vector_t* vector;
56   struct SCC_t* scc;
57   struct MemoryQueue_t* queue;
58   psemaphore parentStallSem;
59   void* seseRec;
60   void* dynID;
61   INTPTR* pointer;
62 } REntry;
63
64 typedef struct MemoryQueueItem_t {
65   int type; // hashtable:0, vector:1, singleitem:2
66   int total;        //total non-retired
67   int status;       //NOTREADY, READY
68   struct MemoryQueueItem_t *next;
69 } MemoryQueueItem;
70
71 typedef struct MemoryQueue_t {
72   MemoryQueueItem * head;
73   MemoryQueueItem * tail;  
74 } MemoryQueue;
75
76 typedef struct BinItem_t {
77   int total;
78   int status;       //NOTREADY, READY
79   int type;         //READBIN:0, WRITEBIN:1
80   struct BinItem_t * next;
81 } BinItem;
82
83 typedef struct Hashtable_t {
84   MemoryQueueItem item;
85   struct BinElement_t* array[NUMBINS];
86   struct Queue*   unresolvedQueue;
87 } Hashtable;
88
89 typedef struct BinElement_t {
90   BinItem * head;
91   BinItem * tail;
92 } BinElement;
93
94 typedef struct WriteBinItem_t {
95   BinItem item;
96   REntry * val;
97 } WriteBinItem;
98
99 typedef struct ReadBinItem_t {
100   BinItem item;
101   REntry * array[NUMREAD];
102   int index;
103 } ReadBinItem;
104
105 typedef struct Vector_t {
106   MemoryQueueItem item;
107   REntry * array[NUMITEMS];
108   int index;
109 } Vector;
110
111 typedef struct SCC_t {
112   MemoryQueueItem item;
113   REntry * val;
114 } SCC;
115
116 int ADDRENTRY(MemoryQueue* q, REntry * r);
117 void RETIRERENTRY(MemoryQueue* Q, REntry * r);
118
119
120 // forward declaration of pointer type
121 typedef struct SESEcommon_t* SESEcommon_p;
122
123 // these fields are common to any SESE, and casting the
124 // generated SESE record to this can be used, because
125 // the common structure is always the first item in a
126 // customized SESE record
127 typedef struct SESEcommon_t {  
128
129   // the identifier for the class of sese's that
130   // are instances of one particular static code block
131   int classID;
132
133   // a parent waits on this semaphore when stalling on
134   // this child, the child gives it at its SESE exit
135   psemaphore stallSem;
136
137   
138   // the lock guards the following data SESE's
139   // use to coordinate with one another
140   pthread_mutex_t lock;
141
142   struct Queue*   forwardList;
143   volatile int             unresolvedDependencies;
144
145   pthread_cond_t  doneCond;
146   int             doneExecuting;
147
148   pthread_cond_t  runningChildrenCond;
149   int             numRunningChildren;
150
151   SESEcommon_p    parent;
152
153   psemaphore parentStallSem;
154   pthread_cond_t stallDone;
155
156   int numMemoryQueue;
157   int rentryIdx;
158   int unresolvedRentryIdx;
159   struct MemoryQueue_t** memoryQueueArray;
160   struct REntry_t* rentryArray[NUMRENTRY];
161   struct REntry_t* unresolvedRentryArray[NUMRENTRY];
162
163 } SESEcommon;
164
165 // a thread-local stack of SESEs and function to
166 // ensure it is initialized once per thread
167 /*
168 extern __thread struct Queue* seseCallStack;
169 extern __thread pthread_once_t mlpOnceObj;
170 void mlpInitOncePerThread();
171 */
172 extern __thread SESEcommon_p seseCaller;
173
174
175 // simple mechanical allocation and 
176 // deallocation of SESE records
177 void* mlpCreateSESErecord( int size );
178 void  mlpDestroySESErecord( void* seseRecord );
179 void* mlpAllocSESErecord( int size );
180
181 MemoryQueue** mlpCreateMemoryQueueArray(int numMemoryQueue);
182 REntry* mlpCreateFineREntry(int type, void* seseToIssue, void* dynID);
183 REntry* mlpCreateREntry(int type, void* seseToIssue);
184 MemoryQueue* createMemoryQueue();
185
186 #endif /* __MLP_RUNTIME__ */