From: bdemsky Date: Wed, 29 Sep 2010 22:23:25 +0000 (+0000) Subject: various hacks... X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=a0dc5f0c98029fd27739ff89c39c532ca26a6d42;p=IRC.git various hacks... clean up cases if we have duplicate... --- diff --git a/Robust/src/Runtime/oooJava/Queue_RCR.c b/Robust/src/Runtime/oooJava/Queue_RCR.c index a8c03424..c7400f6d 100644 --- a/Robust/src/Runtime/oooJava/Queue_RCR.c +++ b/Robust/src/Runtime/oooJava/Queue_RCR.c @@ -37,8 +37,7 @@ void * dequeueRCRQueue() myRCRQueue.size--; return ptr; - } - else + } else return NULL; } diff --git a/Robust/src/Runtime/oooJava/WaitingQueue.c b/Robust/src/Runtime/oooJava/WaitingQueue.c index a96d7494..61669238 100644 --- a/Robust/src/Runtime/oooJava/WaitingQueue.c +++ b/Robust/src/Runtime/oooJava/WaitingQueue.c @@ -17,54 +17,53 @@ WaitingQueueBin * mallocWaitingQueue(int size) { //NOTE: allocSiteID is NOT the same as allocsite, rather it's an ID generated by the traverser for an alloc site for a traversal. void putIntoWaitingQueue(int allocSiteID, WaitingQueueBin * queue, int effectType, void * resumePtr, int traverserID) { - //lock bin - WaitingQueueBinVector * currentVector; - TraverserResumeDataFromWaitingQ * b; - - //since Put SHOULD be done only by 1 thread (from 1 hashtable), the locking mechanism is removed. - WaitingQueueBinVector * head = queue[allocSiteID].head; -// do { -// head = (WaitingQueueBinVector *) 0x1; -// head = LOCKXCHG(&(queue[allocSiteID]).head, head); -// } while (head == (WaitingQueueBinVector *) 0x1); - //now the current bin is locked. - - //completely empty case - if (queue[allocSiteID].tail == NULL) { - currentVector = getUsableWaitingQueueBinVector(); - head = currentVector; - queue[allocSiteID].tail = currentVector; //We do not set the head here because we need lock - } - //Tail bin full - else if (queue[allocSiteID].tail->tailIndex == NUMITEMS_WQ) { - currentVector = getUsableWaitingQueueBinVector(); - queue[allocSiteID].tail->next = currentVector; - queue[allocSiteID].tail = currentVector; - } else { //the bin not full case - currentVector = queue[allocSiteID].tail; - } - - - //For the case in which we try to add the same thing twice - b = &(currentVector->array[currentVector->tailIndex - 1]); - if(b->effectType == effectType && b->resumePtr == resumePtr && b->traverserID == traverserID) { - queue[allocSiteID].head = head; // release lock - return; - } - else {//add item - b = &(currentVector->array[currentVector->tailIndex++]); - + WaitingQueueBin *qptr=&queue[allocSiteID]; + WaitingQueueBinVector * tail = qptr->tail; + + if (tail == NULL) { + //completely empty case + WaitingQueueBinVector * currentVector = getUsableWaitingQueueBinVector(); + TraverserResumeDataFromWaitingQ * b = &(currentVector->array[currentVector->tailIndex++]); + //Add new bin to list + qptr->head = currentVector; + qptr->tail = currentVector; + //Insert item into bin b->resumePtr = resumePtr; b->traverserID = traverserID; b->effectType = effectType; - - queue[allocSiteID].size++; - queue[allocSiteID].head = head; // release lock + qptr->size++; + } else if (tail->tailIndex == NUMITEMS_WQ) { + //Tail bin full + WaitingQueueBinVector * currentVector = tail; + TraverserResumeDataFromWaitingQ * b = &(currentVector->array[currentVector->tailIndex-1]); + //Not a duplicate + if(b->effectType != effectType || b->resumePtr != resumePtr || b->traverserID != traverserID) { + //should add item + currentVector = getUsableWaitingQueueBinVector(); + tail->next = currentVector; + qptr->tail = currentVector; + b = &(currentVector->array[currentVector->tailIndex++]); + b->resumePtr = resumePtr; + b->traverserID = traverserID; + b->effectType = effectType; + qptr->size++; + } + } else { //the bin not full case + WaitingQueueBinVector * currentVector = tail; + TraverserResumeDataFromWaitingQ * b = &(currentVector->array[currentVector->tailIndex-1]); + //Not a duplicate + if(b->effectType != effectType || b->resumePtr != resumePtr || b->traverserID != traverserID) { + //should add item + b = &(currentVector->array[currentVector->tailIndex++]); + b->resumePtr = resumePtr; + b->traverserID = traverserID; + b->effectType = effectType; + qptr->size++; + } } } - int isEmptyForWaitingQ(WaitingQueueBin * queue, int allocSiteID) { return (queue[allocSiteID]).size == 0; }