Fix tabbing.... Please fix your editors so they do tabbing correctly!!! (Spaces...
[IRC.git] / Robust / src / Runtime / oojgarbage.c
1 #ifdef MLP
2 #include "garbage.h"
3 #ifdef SQUEUE
4 #include "squeue.h"
5 #else
6 #include "deque.h"
7 #endif
8 #include "mlp_runtime.h"
9 #include "workschedule.h"
10 extern volatile int numWorkSchedWorkers;
11 extern deque* deques;
12
13 __thread SESEcommon* seseCommon;
14
15 void searchoojroots() {
16 #ifdef SQUEUE
17   {
18     int i;
19     deque*     dq;
20     dequeItem *di;
21     int j;
22
23     // goes over ready-to-run SESEs
24     for( i = 0; i < numWorkSchedWorkers; ++i ) {
25       dq = &(deques[i]);
26
27       di=dq->head;
28
29       do {
30         // check all the relevant indices of this
31         // node in the deque, noting if we are in
32         // the top/bottom node which can be partially
33         // full
34
35         // WHAT?
36         //SESEcommon* common = (SESEcommon*) n->itsDataArr[j];
37         //if(common==seseCommon){
38         // skip the current running SESE
39         //  continue;
40         //}
41         di=(dequeItem *) EXTRACTPTR((INTPTR)di);
42         SESEcommon* seseRec = (SESEcommon*) di->work;
43         if (seseRec!=NULL) {
44           struct garbagelist* gl     = (struct garbagelist*) &(seseRec[1]);
45           struct garbagelist* glroot = gl;
46
47           updateAscendantSESE(seseRec);
48
49           while( gl != NULL ) {
50             int k;
51             for( k = 0; k < gl->size; k++ ) {
52               void* orig = gl->array[k];
53               ENQUEUE(orig, gl->array[k]);
54             }
55             gl = gl->next;
56           }
57         }
58         // we only have to move across the nodes
59         // of the deque if the top and bottom are
60         // not the same already
61         di=di->next;
62       } while( di !=NULL);
63     }
64   }
65 #else
66   {
67     int i;
68     deque*     dq;
69     dequeNode* botNode;
70     int botIndx;
71     dequeNode* topNode;
72     int topIndx;
73     dequeNode* n;
74     int j;
75     int jLo;
76     int jHi;
77
78     // goes over ready-to-run SESEs
79     for( i = 0; i < numWorkSchedWorkers; ++i ) {
80       dq = &(deques[i]);
81
82       botNode = dqDecodePtr(dq->bottom);
83       botIndx = dqDecodeIdx(dq->bottom);
84
85       topNode = dqDecodePtr(dq->top);
86       topIndx = dqDecodeIdx(dq->top);
87
88
89       n = botNode;
90       do {
91         // check all the relevant indices of this
92         // node in the deque, noting if we are in
93         // the top/bottom node which can be partially
94         // full
95         if( n == botNode ) {
96           jLo = botIndx;
97         } else { jLo = 0; }
98         if( n == topNode ) {
99           jHi = topIndx;
100         } else { jHi = DQNODE_ARRAYSIZE; }
101
102         for( j = jLo; j < jHi; ++j ) {
103
104           // WHAT?
105           //SESEcommon* common = (SESEcommon*) n->itsDataArr[j];
106           //if(common==seseCommon){
107           //  continue;
108           //}
109
110           SESEcommon* seseRec = (SESEcommon*) n->itsDataArr[j];
111
112           struct garbagelist* gl     = (struct garbagelist*) &(seseRec[1]);
113           struct garbagelist* glroot = gl;
114
115           updateAscendantSESE(seseRec);
116
117           while( gl != NULL ) {
118             int k;
119             for( k = 0; k < gl->size; k++ ) {
120               void* orig = gl->array[k];
121               ENQUEUE(orig, gl->array[k]);
122             }
123             gl = gl->next;
124           }
125         }
126
127         // we only have to move across the nodes
128         // of the deque if the top and bottom are
129         // not the same already
130         if( botNode != topNode ) {
131           n = n->next;
132         }
133       } while( n != topNode );
134     }
135   }
136 #endif
137 }
138
139 updateForwardList(struct Queue *forwardList, int prevUpdate) {
140   struct QueueItem * fqItem=getHead(forwardList);
141   while(fqItem!=NULL) {
142     SESEcommon* seseRec = (SESEcommon*)(fqItem->objectptr);
143     struct garbagelist * gl=(struct garbagelist *)&(seseRec[1]);
144     if(prevUpdate==TRUE) {
145       updateAscendantSESE(seseRec);
146     }
147     // do something here
148     while(gl!=NULL) {
149       int i;
150       for(i=0; i<gl->size; i++) {
151         void * orig=gl->array[i];
152         ENQUEUE(orig, gl->array[i]);
153       }
154       gl=gl->next;
155     }
156     // iterate forwarding list of seseRec
157     struct Queue* fList=&seseRec->forwardList;
158     updateForwardList(fList,prevUpdate);
159     fqItem=getNextQueueItem(fqItem);
160   }
161
162 }
163
164 updateMemoryQueue(SESEcommon* seseParent) {
165   // update memory queue
166   int i,binidx;
167   for(i=0; i<seseParent->numMemoryQueue; i++) {
168     MemoryQueue *memoryQueue=seseParent->memoryQueueArray[i];
169     MemoryQueueItem *memoryItem=memoryQueue->head;
170     while(memoryItem!=NULL) {
171       if(memoryItem->type==HASHTABLE) {
172         Hashtable *ht=(Hashtable*)memoryItem;
173         for(binidx=0; binidx<NUMBINS; binidx++) {
174           BinElement *bin=ht->array[binidx];
175           BinItem *binItem=bin->head;
176           while(binItem!=NULL) {
177             if(binItem->type==READBIN) {
178               ReadBinItem* readBinItem=(ReadBinItem*)binItem;
179               int ridx;
180               for(ridx=0; ridx<readBinItem->index; ridx++) {
181                 REntry *rentry=readBinItem->array[ridx];
182                 SESEcommon* seseRec = (SESEcommon*)(rentry->seseRec);
183                 struct garbagelist * gl= (struct garbagelist *)&(seseRec[1]);
184                 updateAscendantSESE(seseRec);
185                 while(gl!=NULL) {
186                   int i;
187                   for(i=0; i<gl->size; i++) {
188                     void * orig=gl->array[i];
189                     ENQUEUE(orig, gl->array[i]);
190                   }
191                   gl=gl->next;
192                 }
193               }
194             } else { //writebin
195               REntry *rentry=((WriteBinItem*)binItem)->val;
196               SESEcommon* seseRec = (SESEcommon*)(rentry->seseRec);
197               struct garbagelist * gl= (struct garbagelist *)&(seseRec[1]);
198               updateAscendantSESE(seseRec);
199               while(gl!=NULL) {
200                 int i;
201                 for(i=0; i<gl->size; i++) {
202                   void * orig=gl->array[i];
203                   ENQUEUE(orig, gl->array[i]);
204                 }
205                 gl=gl->next;
206               }
207             }
208             binItem=binItem->next;
209           }
210         }
211       } else if(memoryItem->type==VECTOR) {
212         Vector *vt=(Vector*)memoryItem;
213         int idx;
214         for(idx=0; idx<vt->index; idx++) {
215           REntry *rentry=vt->array[idx];
216           if(rentry!=NULL) {
217             SESEcommon* seseRec = (SESEcommon*)(rentry->seseRec);
218             struct garbagelist * gl= (struct garbagelist *)&(seseRec[1]);
219             updateAscendantSESE(seseRec);
220             while(gl!=NULL) {
221               int i;
222               for(i=0; i<gl->size; i++) {
223                 void * orig=gl->array[i];
224                 ENQUEUE(orig, gl->array[i]);
225               }
226               gl=gl->next;
227             }
228           }
229         }
230       } else if(memoryItem->type==SINGLEITEM) {
231         SCC *scc=(SCC*)memoryItem;
232         REntry *rentry=scc->val;
233         if(rentry!=NULL) {
234           SESEcommon* seseRec = (SESEcommon*)(rentry->seseRec);
235           struct garbagelist * gl= (struct garbagelist *)&(seseRec[1]);
236           updateAscendantSESE(seseRec);
237           while(gl!=NULL) {
238             int i;
239             for(i=0; i<gl->size; i++) {
240               void * orig=gl->array[i];
241               ENQUEUE(orig, gl->array[i]);
242             }
243             gl=gl->next;
244           }
245         }
246       }
247       memoryItem=memoryItem->next;
248     }
249   }
250 }
251
252 updateAscendantSESE(SESEcommon* seseRec) {
253   int prevIdx;
254   for(prevIdx=0; prevIdx<(seseRec->numDependentSESErecords); prevIdx++) {
255     SESEcommon* prevSESE = (SESEcommon*)
256                            (
257       ((INTPTR)seseRec) +
258       seseRec->offsetToDepSESErecords +
259       (sizeof(INTPTR)*prevIdx)
260                            );
261
262     if(prevSESE!=NULL) {
263       struct garbagelist * prevgl=(struct garbagelist *)&(((SESEcommon*)(prevSESE))[1]);
264       while(prevgl!=NULL) {
265         int i;
266         for(i=0; i<prevgl->size; i++) {
267           void * orig=prevgl->array[i];
268           ENQUEUE(orig, prevgl->array[i]);
269         }
270         prevgl=prevgl->next;
271       }
272     }
273   }
274 }
275 #endif