8 #include "mlp_runtime.h"
9 #include "workschedule.h"
10 #include "methodheaders.h"
15 __thread struct Queue* seseCallStack;
16 __thread pthread_once_t mlpOnceObj = PTHREAD_ONCE_INIT;
17 void mlpInitOncePerThread() {
18 seseCallStack = createQueue();
21 __thread SESEcommon_p seseCaller;
24 void* mlpAllocSESErecord( int size ) {
25 void* newrec = RUNMALLOC( size );
27 printf( "mlpAllocSESErecord did not obtain memory!\n" );
34 void mlpFreeSESErecord( void* seseRecord ) {
35 RUNFREE( seseRecord );
38 MemoryQueue** mlpCreateMemoryQueueArray(int numMemoryQueue){
40 MemoryQueue** newMemoryQueue=(MemoryQueue**)RUNMALLOC( sizeof( MemoryQueue* ) * numMemoryQueue );
41 for(i=0; i<numMemoryQueue; i++){
42 newMemoryQueue[i]=createMemoryQueue();
44 return newMemoryQueue;
47 REntry* mlpCreateREntryArray(){
48 REntry* newREntryArray=(REntry*)RUNMALLOC(sizeof(REntry)*NUMRENTRY);
49 return newREntryArray;
52 REntry* mlpCreateFineREntry(int type, void* seseToIssue, void* dynID){
53 REntry* newREntry=(REntry*)RUNMALLOC(sizeof(REntry));
55 newREntry->seseRec=seseToIssue;
56 newREntry->pointer=dynID;
57 if((*newREntry->pointer)!=0){// make sure it is not unresolved address.
58 struct ___Object___ * obj=(struct ___Object___*)((unsigned INTPTR)*newREntry->pointer);
59 newREntry->oid=obj->oid;
64 REntry* mlpCreateREntry(int type, void* seseToIssue){
65 REntry* newREntry=(REntry*)RUNMALLOC(sizeof(REntry));
67 newREntry->seseRec=seseToIssue;
71 int isParent(REntry *r) {
72 if (r->type==PARENTREAD || r->type==PARENTWRITE) {
79 int isParentCoarse(REntry *r){
80 if (r->type==PARENTCOARSE){
87 int isFineRead(REntry *r) {
88 if (r->type==READ || r->type==PARENTREAD) {
95 int isFineWrite(REntry *r) {
96 if (r->type==WRITE || r->type==PARENTWRITE) {
103 int isCoarse(REntry *r){
104 if(r->type==COARSE || r->type==PARENTCOARSE){
111 int isSCC(REntry *r){
112 if(r->type==SCCITEM){
119 int isSingleItem(MemoryQueueItem *qItem){
120 if(qItem->type==SINGLEITEM){
127 int isHashtable(MemoryQueueItem *qItem){
128 if(qItem->type==HASHTABLE){
135 int isVector(MemoryQueueItem *qItem){
136 if(qItem->type==VECTOR){
143 int isReadBinItem(BinItem* b){
144 if(b->type==READBIN){
151 int isWriteBinItem(BinItem* b){
152 if(b->type==WRITEBIN){
159 int generateKey(unsigned int data){
160 return (data&H_MASK)>> 4;
163 Hashtable* createHashtable(){
165 Hashtable* newTable=(Hashtable*)RUNMALLOC(sizeof(Hashtable));
166 newTable->item.type=HASHTABLE;
167 for(i=0;i<NUMBINS;i++){
168 newTable->array[i]=(BinElement*)RUNMALLOC(sizeof(BinElement));
169 newTable->array[i]->head=NULL;
170 newTable->array[i]->tail=NULL;
172 newTable->unresolvedQueue=NULL;
176 WriteBinItem* createWriteBinItem(){
177 WriteBinItem* binitem=(WriteBinItem*)RUNMALLOC(sizeof(WriteBinItem));
178 binitem->item.type=WRITEBIN;
182 ReadBinItem* createReadBinItem(){
183 ReadBinItem* binitem=(ReadBinItem*)RUNMALLOC(sizeof(ReadBinItem));
185 binitem->item.type=READBIN;
189 Vector* createVector(){
190 Vector* vector=(Vector*)RUNMALLOC(sizeof(Vector));
192 vector->item.type=VECTOR;
197 SCC* scc=(SCC*)RUNMALLOC(sizeof(SCC));
198 scc->item.type=SINGLEITEM;
202 MemoryQueue* createMemoryQueue(){
203 MemoryQueue* queue = (MemoryQueue*)RUNMALLOC(sizeof(MemoryQueue));
204 MemoryQueueItem* dummy=(MemoryQueueItem*)RUNMALLOC(sizeof(MemoryQueueItem));
205 dummy->type=3; // dummy type
213 int ADDRENTRY(MemoryQueue * q, REntry * r) {
214 if (isFineRead(r) || isFineWrite(r)) {
215 return ADDTABLE(q, r);
216 } else if (isCoarse(r)) {
217 return ADDVECTOR(q, r);
218 } else if (isSCC(r)) {
223 int ADDTABLE(MemoryQueue *q, REntry *r) {
224 if(!isHashtable(q->tail)) {
226 MemoryQueueItem* tail=q->tail;
227 if (isParent(r) && tail->total==0 && q->tail==q->head) {
232 Hashtable* h=createHashtable();
233 tail->next=(MemoryQueueItem*)h;
234 //************NEED memory barrier here to ensure compiler does not cache Q.tail.status********
235 if (BARRIER() && tail->status==READY && tail->total==0 && q->tail==q->head) {
236 //previous Q item is finished
237 h->item.status=READY;
239 q->tail=(MemoryQueueItem*)h;
240 // handle the the queue item case
241 if(q->head->type==3){
242 q->head=(MemoryQueueItem*)h;
246 //at this point, have table
247 Hashtable* table=(Hashtable*)q->tail;
248 r->hashtable=table; // set rentry's hashtable
249 if((*(r->pointer)==0 || (*(r->pointer)!=0 && BARRIER() && table->unresolvedQueue!=NULL))){
251 // grab lock on the queue
253 val=(struct Queue*)0x1;
254 val=(struct Queue*)LOCKXCHG((unsigned INTPTR*)&(table->unresolvedQueue), (unsigned INTPTR)val);
255 } while(val==(struct Queue*)0x1);
257 //queue is null, first case
258 if(*(r->pointer)!=0){
259 // check whether pointer is already resolved, or not.
260 table->unresolvedQueue=NULL; //released lock;
261 return ADDTABLEITEM(table,r,TRUE);
263 struct Queue* queue=createQueue();
264 addNewItemBack(queue,r);
265 atomic_inc(&table->item.total);
266 table->unresolvedQueue=queue; // expose new queue
268 // add unresolved rentry at the end of the queue.
269 addNewItemBack(val,r);
270 atomic_inc(&table->item.total);
271 table->unresolvedQueue=val; // released lock
276 //int key=generateKey((unsigned int)(unsigned INTPTR)*(r->pointer));
277 int key=generateKey(r->oid);
280 BinElement* bin=table->array[key];
281 val=(BinItem*)LOCKXCHG((unsigned INTPTR*)&(bin->head), (unsigned INTPTR)val);//note...talk to me about optimizations here.
282 } while(val==(BinItem*)0x1);
283 //at this point have locked bin
285 return EMPTYBINCASE(table, table->array[key], r, TRUE);
287 if (isFineWrite(r)) {
288 return WRITEBINCASE(table, r, val, key, TRUE);
289 } else if (isFineRead(r)) {
290 return READBINCASE(table, r, val, key, TRUE);
295 int ADDTABLEITEM(Hashtable* table, REntry* r, int inc){
298 // int key=generateKey((unsigned int)(unsigned INTPTR)*(r->pointer));
299 int key=generateKey(r->oid);
302 BinElement* bin=table->array[key];
303 val=(BinItem*)LOCKXCHG((unsigned INTPTR*)&(bin->head), (unsigned INTPTR)val);
304 } while(val==(BinItem*)0x1);
305 //at this point have locked bin
307 return EMPTYBINCASE(table, table->array[key], r, inc);
309 if (isFineWrite(r)) {
310 return WRITEBINCASE(table, r, val, key, inc);
311 } else if (isFineRead(r)) {
312 return READBINCASE(table, r, val, key, inc);
317 int EMPTYBINCASE(Hashtable *T, BinElement* be, REntry *r, int inc) {
320 if (isFineWrite(r)) {
321 b=(BinItem*)createWriteBinItem();
322 ((WriteBinItem*)b)->val=r;//<-only different statement
323 } else if (isFineRead(r)) {
324 b=(BinItem*)createReadBinItem();
325 ReadBinItem* readbin=(ReadBinItem*)b;
326 readbin->array[readbin->index++]=r;
330 if (T->item.status==READY) {
331 //current entry is ready
335 be->head=NULL; // released lock
344 atomic_inc(&T->item.total);
349 be->head=b;//released lock
353 int WRITEBINCASE(Hashtable *T, REntry *r, BinItem *val, int key, int inc) {
354 //chain of bins exists => tail is valid
355 //if there is something in front of us, then we are not ready
358 BinElement* be=T->array[key];
360 BinItem *bintail=be->tail;
362 WriteBinItem *b=createWriteBinItem();
366 // note: If current table clears all dependencies, then write bin is ready
367 if (T->item.total==0){
372 b->item.status=retval;
373 // b->item.status=NOTREADY;
376 atomic_inc(&T->item.total);
380 r->binitem=(BinItem*)b;
382 be->tail->next=(BinItem*)b;
383 be->tail=(BinItem*)b;
388 READBINCASE(Hashtable *T, REntry *r, BinItem *val, int key, int inc) {
389 BinItem * bintail=T->array[key]->tail;
390 if (isReadBinItem(bintail)) {
391 return TAILREADCASE(T, r, val, bintail, key, inc);
392 } else if (!isReadBinItem(bintail)) {
393 TAILWRITECASE(T, r, val, bintail, key, inc);
398 int TAILREADCASE(Hashtable *T, REntry *r, BinItem *val, BinItem *bintail, int key, int inc) {
399 ReadBinItem * readbintail=(ReadBinItem*)T->array[key]->tail;
401 if (readbintail->item.status==READY) {
405 T->array[key]->head=val;//released lock
413 if (readbintail->index==NUMREAD) { // create new read group
414 ReadBinItem* rb=createReadBinItem();
415 rb->array[rb->index++]=r;
416 rb->item.total=1;//safe only because item could not have started
417 rb->item.status=status;
418 T->array[key]->tail->next=(BinItem*)rb;
419 T->array[key]->tail=(BinItem*)rb;
420 r->binitem=(BinItem*)rb;
421 } else { // group into old tail
422 readbintail->array[readbintail->index++]=r;
423 atomic_inc(&readbintail->item.total);
424 r->binitem=(BinItem*)readbintail;
425 //printf("grouping with %d\n",readbintail->index);
428 atomic_inc(&T->item.total);
431 T->array[key]->head=val;//released lock
435 TAILWRITECASE(Hashtable *T, REntry *r, BinItem *val, BinItem *bintail, int key, int inc) {
436 // WriteBinItem* wb=createWriteBinItem();
438 //wb->item.total=1;//safe because item could not have started
439 //wb->item.status=NOTREADY;
440 ReadBinItem* rb=createReadBinItem();
441 rb->array[rb->index++]=r;
442 rb->item.total=1;//safe because item could not have started
443 rb->item.status=NOTREADY;
445 atomic_inc(&T->item.total);
448 r->binitem=(BinItem*)rb;
449 T->array[key]->tail->next=(BinItem*)rb;
450 T->array[key]->tail=(BinItem*)rb;
451 T->array[key]->head=val;//released lock
454 ADDVECTOR(MemoryQueue *Q, REntry *r) {
455 if(!isVector(Q->tail)) {
457 if (isParentCoarse(r) && Q->tail->total==0 && Q->tail==Q->head) {
462 Vector* V=createVector();
463 Q->tail->next=(MemoryQueueItem*)V;
464 //************NEED memory barrier here to ensure compiler does not cache Q.tail.status******
465 if (BARRIER() && Q->tail->status==READY&&Q->tail->total==0) {
466 //previous Q item is finished
467 V->item.status=READY;
469 Q->tail=(MemoryQueueItem*)V;
470 // handle the the queue item case
471 if(Q->head->type==3){
472 Q->head=(MemoryQueueItem*)V;
475 //at this point, have vector
476 Vector* V=(Vector*)Q->tail;
477 if (V->index==NUMITEMS) {
481 V->item.status=NOTREADY;
482 Q->tail->next=(MemoryQueueItem*)V;
483 //***NEED memory barrier here to ensure compiler does not cache Q.tail.status******
484 if (BARRIER() && Q->tail->status==READY) {
485 V->item.status=READY;
487 Q->tail=(MemoryQueueItem*)V;
490 atomic_inc(&V->item.total);
494 //*****NEED memory barrier here to ensure compiler does not reorder writes to V.array and V.index
497 //*****NEED memory barrier here to ensure compiler does not cache V.status*********
499 if (BARRIER() && V->item.status==READY) {
501 flag=(void*)LOCKXCHG((unsigned INTPTR*)&(V->array[index]), (unsigned INTPTR)flag);
503 if (isParent(r)) { //parent's retire immediately
504 atomic_dec(&V->item.total);
508 return NOTREADY;//<- means that some other dispatcher got this one...so need to do accounting correctly
516 //SCC's don't come in parent variety
517 ADDSCC(MemoryQueue *Q, REntry *r) {
523 Q->tail->next=(MemoryQueueItem*)S;
524 //*** NEED BARRIER HERE
525 if (BARRIER() && Q->tail->status==READY && Q->tail->total==0 && Q->tail==Q->head) {
526 //previous Q item is finished
527 S->item.status=READY;
528 Q->tail=(MemoryQueueItem*)S;
529 // handle the the queue item case
530 if(Q->head->type==3){
531 Q->head=(MemoryQueueItem*)S;
534 flag=(void*)LOCKXCHG((unsigned INTPTR*)&(S->val), (unsigned INTPTR)flag);
538 return NOTREADY;//<- means that some other dispatcher got this one...so need to do accounting correctly
541 Q->tail=(MemoryQueueItem*)S;
547 void RETIRERENTRY(MemoryQueue* Q, REntry * r) {
548 if (isFineWrite(r)||isFineRead(r)) {
549 RETIREHASHTABLE(Q, r);
550 } else if (isCoarse(r)) {
552 } else if (isSCC(r)) {
557 RETIRESCC(MemoryQueue *Q, REntry *r) {
559 s->item.total=0;//don't need atomicdec
564 RETIREHASHTABLE(MemoryQueue *q, REntry *r) {
565 Hashtable *T=r->hashtable;
566 BinItem *b=r->binitem;
568 atomic_dec(&T->item.total);
569 if (T->item.next!=NULL && T->item.total==0) {
574 RETIREBIN(Hashtable *T, REntry *r, BinItem *b) {
575 // int key=generateKey((unsigned int)(unsigned INTPTR)*(r->pointer));
576 int key=generateKey(r->oid);
578 atomic_dec(&b->total);
580 if (isFineWrite(r) || (isFineRead(r) && b->next!=NULL && b->total==0)) {
581 // CHECK FIRST IF next is nonnull to guarantee that b.total cannot change
585 val=(BinItem*)LOCKXCHG((unsigned INTPTR*)&(T->array[key]->head), (unsigned INTPTR)val);
586 } while(val==(BinItem*)0x1);
587 // at this point have locked bin
592 if (isReadBinItem(ptr)) {
593 ReadBinItem* rptr=(ReadBinItem*)ptr;
594 if (rptr->item.status==NOTREADY) {
595 for (i=0;i<rptr->index;i++) {
596 resolveDependencies(rptr->array[i]);
597 if (isParent(rptr->array[i])) {
598 //parents go immediately
599 atomic_dec(&rptr->item.total);
600 atomic_dec(&T->item.total);
604 rptr->item.status=READY;
605 if (rptr->item.next==NULL) {
608 if (rptr->item.total!=0) {
610 } else if ((BinItem*)rptr==val) {
613 } else if(isWriteBinItem(ptr)) {
616 if(ptr->status==NOTREADY){
617 resolveDependencies(((WriteBinItem*)ptr)->val);
619 if(isParent(((WriteBinItem*)ptr)->val)){
620 atomic_dec(&T->item.total);
624 }else{ // write bin is already resolved
628 if(ptr->status==NOTREADY) {
629 resolveDependencies(((WriteBinItem*)ptr)->val);
632 if (isParent(((WriteBinItem*)ptr)->val)) {
633 atomic_dec(&T->item.total);
643 T->array[key]->head=val; // release lock
648 RETIREVECTOR(MemoryQueue *Q, REntry *r) {
650 atomic_dec(&V->item.total);
651 if (V->item.next!=NULL && V->item.total==0) { //NOTE: ORDERING CRUCIAL HERE
656 RESOLVECHAIN(MemoryQueue *Q) {
658 MemoryQueueItem* head=Q->head;
659 if (head->next==NULL||head->total!=0) {
660 //item is not finished
661 if (head->status!=READY) {
662 //need to update status
664 if (isHashtable(head)) {
665 RESOLVEHASHTABLE(Q, head);
666 } else if (isVector(head)) {
667 RESOLVEVECTOR(Q, head);
668 } else if (isSingleItem(head)) {
671 if (head->next==NULL)
678 MemoryQueueItem* nextitem=head->next;
679 CAS((unsigned INTPTR*)&(Q->head), (unsigned INTPTR)head, (unsigned INTPTR)nextitem);
680 //oldvalue not needed... if we fail we just repeat
685 RESOLVEHASHTABLE(MemoryQueue *Q, Hashtable *T) {
687 for (binidx=0;binidx<NUMBINS;binidx++) {
688 BinElement* bin=T->array[binidx];
692 val=(BinItem*)LOCKXCHG((unsigned INTPTR*)&(bin->head), (unsigned INTPTR)val);
693 } while (val==(BinItem*)1);
694 //at this point have locked bin
697 if(ptr!=NULL&&ptr->status==NOTREADY) {
699 if (isWriteBinItem(ptr)) {
702 resolveDependencies(((WriteBinItem*)ptr)->val);
704 if (isParent(((WriteBinItem*)ptr)->val)) {
705 atomic_dec(&T->item.total);
709 } else if (isReadBinItem(ptr)) {
711 ReadBinItem* rptr=(ReadBinItem*)ptr;
712 for(i=0;i<rptr->index;i++) {
713 resolveDependencies(rptr->array[i]);
714 if (isParent(rptr->array[i])) {
715 atomic_dec(&rptr->item.total);
716 atomic_dec(&T->item.total);
719 if (rptr->item.next==NULL||rptr->item.total!=0) {
721 } else if((BinItem*)rptr==val) {
724 rptr->item.status=READY; {
730 bin->head=val; // released lock;
734 RESOLVEVECTOR(MemoryQueue *q, Vector *V) {
740 for (i=0;i<NUMITEMS;i++) {
742 val=(REntry*)LOCKXCHG((unsigned INTPTR*)&(tmp->array[i]), (unsigned INTPTR)val);
744 resolveDependencies(val);
746 atomic_dec(&tmp->item.total);
750 if (tmp->item.next!=NULL&&isVector(tmp->item.next)) {
751 tmp=(Vector*)tmp->item.next;
759 //precondition: SCC's state is READY
761 flag=(void*)LOCKXCHG((unsigned INTPTR*)&(S->val), (unsigned INTPTR)flag);
763 resolveDependencies(flag);
768 resolveDependencies(REntry* rentry){
769 SESEcommon* seseCommon=(SESEcommon*)rentry->seseRec;
770 if(rentry->type==READ || rentry->type==WRITE || rentry->type==COARSE || rentry->type==SCCITEM){
771 if( atomic_sub_and_test(1, &(seseCommon->unresolvedDependencies)) ){
772 workScheduleSubmit(seseCommon);
774 }else if(rentry->type==PARENTREAD || rentry->type==PARENTWRITE ||rentry->type==PARENTCOARSE){
775 psem_give(&(rentry->parentStallSem));
779 void INITIALIZEBUF(MemoryQueue * q){
781 for(i=0; i<NUMBINS; i++){
787 void ADDRENTRYTOBUF(MemoryQueue * q, REntry * r){
788 q->buf[q->bufcount]=r;
792 int RESOLVEBUFFORHASHTABLE(MemoryQueue * q, Hashtable* table, SESEcommon *seseCommon){
794 // first phase: only consider write rentry
795 for(i=0; i<q->bufcount;i++){
798 int key=generateKey(r->oid);
799 if(q->binbuf[key]==NULL){
800 // for multiple writes, add only the first write that hashes to the same bin
807 // second phase: enqueue read items if it is eligible
808 for(i=0; i<q->bufcount;i++){
810 if(r!=NULL && r->type==READ){
811 int key=generateKey(r->oid);
812 if(q->binbuf[key]==NULL){
813 // read item that hashes to the bin which doen't contain any write
814 seseCommon->rentryArray[seseCommon->rentryIdx++]=r;
815 if(ADDTABLEITEM(table, r, FALSE)==READY){
816 resolveDependencies(r);
823 // then, add only one of write items that hashes to the same bin
824 for(i=0; i<q->bufcount;i++){
827 seseCommon->rentryArray[seseCommon->rentryIdx++]=r;
828 if(ADDTABLEITEM(table, r, FALSE)==READY){
829 resolveDependencies(r);
835 int RESOLVEBUF(MemoryQueue * q, SESEcommon *seseCommon){
838 // check if every waiting entry is resolved
839 // if not, defer every items for hashtable until it is resolved.
840 int unresolved=FALSE;
841 for(i=0; i<q->bufcount;i++){
843 if(*(r->pointer)==0){
847 if(unresolved==TRUE){
848 for(i=0; i<q->bufcount;i++){
852 if(ADDRENTRY(q,r)==NOTREADY){
859 // first phase: only consider write rentry
860 for(i=0; i<q->bufcount;i++){
863 int key=generateKey(r->oid);
864 if(q->binbuf[key]==NULL){
865 // for multiple writes, add only the first write that hashes to the same bin
872 // second phase: enqueue read items if it is eligible
873 for(i=0; i<q->bufcount;i++){
875 if(r!=NULL && r->type==READ){
876 int key=generateKey(r->oid);
877 if(q->binbuf[key]==NULL){
878 // read item that hashes to the bin which doen't contain any write
879 seseCommon->rentryArray[seseCommon->rentryIdx++]=r;
880 if(ADDRENTRY(q,r)==NOTREADY){
888 // then, add only one of write items that hashes to the same bin
889 for(i=0; i<q->bufcount;i++){
892 seseCommon->rentryArray[seseCommon->rentryIdx++]=r;
893 if(ADDRENTRY(q,r)==NOTREADY){
902 resolvePointer(REntry* rentry){
904 Hashtable* table=rentry->hashtable;
907 //resolved already before related rentry is enqueued to the waiting queue
912 val=(struct Queue*)0x1;
913 val=(struct Queue*)LOCKXCHG((unsigned INTPTR*)&(table->unresolvedQueue), (unsigned INTPTR)val);
914 } while(val==(struct Queue*)0x1);
915 if(val!=NULL && getHead(val)->objectptr==rentry){
916 // handling pointer is the first item of the queue
917 // start to resolve until it reaches unresolved pointer or end of queue
918 INTPTR currentSESE=0;
920 struct QueueItem* head=getHead(val);
922 REntry* rentry=(REntry*)head->objectptr;
923 if(*(rentry->pointer)==0){
924 // encounters following unresolved pointer
925 table->unresolvedQueue=val;//released lock
928 removeItem(val,head);
929 //now, address is resolved. update OID field.
930 struct ___Object___ * obj=(struct ___Object___*)((unsigned INTPTR)*rentry->pointer);
931 rentry->oid=obj->oid;
933 //check if rentry is buffer mode
934 if(rentry->isBufMode==TRUE){
937 INITIALIZEBUF(queue);
938 currentSESE=(INTPTR)rentry;
939 ADDRENTRYTOBUF(queue,rentry);
940 } else if(currentSESE==(INTPTR)rentry){
941 ADDRENTRYTOBUF(queue,rentry);
942 } else if(currentSESE!=(INTPTR)rentry){
943 RESOLVEBUFFORHASHTABLE(queue,table,(SESEcommon*)rentry->seseRec);
944 currentSESE=(INTPTR)rentry;
945 INITIALIZEBUF(queue);
946 ADDRENTRYTOBUF(rentry->queue,rentry);
950 //previous SESE has buf mode, need to invoke resolve buffer
951 RESOLVEBUFFORHASHTABLE(queue,table,(SESEcommon*)rentry->seseRec);
955 if(ADDTABLEITEM(table, rentry, FALSE)==READY){
956 resolveDependencies(rentry);
960 table->unresolvedQueue=NULL; // set hashtable as normal-mode.
965 // resolved rentry is not head of queue
966 table->unresolvedQueue=val;//released lock;
970 void rehashMemoryQueue(SESEcommon_p seseParent){
971 // update memory queue
973 for(i=0; i<seseParent->numMemoryQueue; i++){
974 MemoryQueue *memoryQueue=seseParent->memoryQueueArray[i];
975 MemoryQueueItem *memoryItem=memoryQueue->head;
976 MemoryQueueItem *prevItem=NULL;
977 while(memoryItem!=NULL){
978 if(memoryItem->type==HASHTABLE){
980 Hashtable* ht=(Hashtable*)memoryItem;
981 Hashtable* newht=createHashtable();
983 for(binidx=0; binidx<NUMBINS; binidx++){
984 BinElement *bin=ht->array[binidx];
985 BinItem *binItem=bin->head;
986 //traverse over the list of each bin
987 while(binItem!=NULL){
988 if(binItem->type==READBIN){
989 ReadBinItem* readBinItem=(ReadBinItem*)binItem;
991 for(ridx=0; ridx<readBinItem->index; ridx++){
992 REntry *rentry=readBinItem->array[ridx];
993 int newkey=generateKey((unsigned int)(unsigned INTPTR)*(rentry->pointer));
994 int status=rentry->binitem->status;
995 ADDTABLEITEM(newht,rentry,TRUE);
996 rentry->binitem->status=status; // update bin status as before rehash
999 REntry *rentry=((WriteBinItem*)binItem)->val;
1000 int newkey=generateKey((unsigned int)(unsigned INTPTR)*(rentry->pointer));
1001 int status=rentry->binitem->status;
1002 ADDTABLEITEM(newht,rentry,TRUE);
1003 int newstatus=rentry->binitem->status;
1004 //printf("[%d]old status=%d new status=%d\n",i,status,newstatus);
1005 rentry->binitem->status=status; // update bin status as before rehash
1007 binItem=binItem->next;
1010 newht->item.status=ht->item.status; // update hashtable status
1012 prevItem->next=(MemoryQueueItem*)newht;
1014 if(memoryQueue->head==memoryQueue->tail){
1015 memoryQueue->tail=(MemoryQueueItem*)newht;
1017 memoryQueue->head=(MemoryQueueItem*)newht;
1019 newht->item.next=ht->item.next;
1021 prevItem=memoryItem;
1022 memoryItem=memoryItem->next;