From: bdemsky Date: Wed, 23 Mar 2011 23:52:28 +0000 (+0000) Subject: get rid of length field.... X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=17a19a0217acacb6965eeb8e42cbc5272515c22f;p=IRC.git get rid of length field.... --- diff --git a/Robust/src/Runtime/oooJava/Queue_RCR.c b/Robust/src/Runtime/oooJava/Queue_RCR.c index 745861ac..bf499543 100644 --- a/Robust/src/Runtime/oooJava/Queue_RCR.c +++ b/Robust/src/Runtime/oooJava/Queue_RCR.c @@ -7,40 +7,40 @@ __thread struct RCRQueue myRCRQueue; void resetRCRQueue() { myRCRQueue.head = 0; myRCRQueue.tail = 0; - myRCRQueue.length = 0; } //0 would mean success //1 would mean fail int enqueueRCRQueue(void * ptr, int traverserState) { - if (myRCRQueue.length & SIZE) - return 1; + unsigned int oldhead=myRCRQueue.head+1; + unsigned int head=oldhead; + if (head&SIZE) + head=0; - myRCRQueue.length++; - myRCRQueue.elements[myRCRQueue.head].object = ptr; - myRCRQueue.elements[myRCRQueue.head].traverserState = traverserState; - myRCRQueue.head++; - - if (myRCRQueue.head&SIZE) - myRCRQueue.head=0; + if (head==myRCRQueue.tail) + return 1; + myRCRQueue.elements[oldhead].object = ptr; + myRCRQueue.elements[oldhead].traverserState = traverserState; + myRCRQueue.head=head; return 0; } RCRQueueEntry * dequeueRCRQueue() { - if(!myRCRQueue.length) + unsigned int tail=myRCRQueue.tail; + if(myRCRQueue.head==tail) return NULL; - - myRCRQueue.length--; - void * ptr = &myRCRQueue.elements[myRCRQueue.tail++]; - if(myRCRQueue.tail & SIZE) - myRCRQueue.tail = 0; + RCRQueueEntry * ptr = &myRCRQueue.elements[tail]; + tail++; + if (tail & SIZE) + tail=0; + myRCRQueue.tail=tail; return ptr; } int isEmptyRCRQueue() { - return !myRCRQueue.length; + return myRCRQueue.head==myRCRQueue.tail; } diff --git a/Robust/src/Runtime/oooJava/Queue_RCR.h b/Robust/src/Runtime/oooJava/Queue_RCR.h index fa91cbca..b06d53ec 100644 --- a/Robust/src/Runtime/oooJava/Queue_RCR.h +++ b/Robust/src/Runtime/oooJava/Queue_RCR.h @@ -14,7 +14,6 @@ struct RCRQueue { RCRQueueEntry elements[SIZE]; unsigned int head; unsigned int tail; - unsigned int length; }; int enqueueRCRQueue(void * ptr, int traverserState);