From: stephey Date: Wed, 28 Jul 2010 22:06:12 +0000 (+0000) Subject: Added Runtime C files for Queue to be used in Runtime Conflict Resolver X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=38b49e01012060cca86f420d8a5a4ec8ee5f8cae;p=IRC.git Added Runtime C files for Queue to be used in Runtime Conflict Resolver --- diff --git a/Robust/src/Runtime/oooJava/Queue_RCR.c b/Robust/src/Runtime/oooJava/Queue_RCR.c new file mode 100644 index 00000000..d43653b7 --- /dev/null +++ b/Robust/src/Runtime/oooJava/Queue_RCR.c @@ -0,0 +1,58 @@ +#include "Queue_RCR.h" +#include "stdlib.h" +#include "stdio.h" + +//2^14 =16384 = 0X4000 +#define SIZE 16384 + +__thread struct RCRQueue myRCRQueue; + +void resetRCRQueue() +{ + myRCRQueue.head = 0; + myRCRQueue.tail = 0; + myRCRQueue.size = 0; +} + + +//0 would mean sucess +//1 would mean fail +//since if we reach SIZE, we will stop operation, it doesn't matter +//that we overwrite the element in the queue +int enqueueRCRQueue(void * ptr) +{ + myRCRQueue.elements[myRCRQueue.head++] = ptr; + + if(myRCRQueue.head & 0x4000) + myRCRQueue.head = 0; + + return myRCRQueue.size++ == SIZE; +} + +void * dequeueRCRQueue() +{ + if(myRCRQueue.size) { + void * ptr = myRCRQueue.elements[myRCRQueue.tail++]; + + if(myRCRQueue.tail & 0x4000) + myRCRQueue.tail = 0; + + + myRCRQueue.size--; + return ptr; + } + else + return NULL; +} + +int isEmptyRCRQueue() +{ + return !myRCRQueue.size; +} + +int getSizeRCRQueue() +{ + return myRCRQueue.size; +} + + diff --git a/Robust/src/Runtime/oooJava/Queue_RCR.h b/Robust/src/Runtime/oooJava/Queue_RCR.h new file mode 100644 index 00000000..c1a1fb87 --- /dev/null +++ b/Robust/src/Runtime/oooJava/Queue_RCR.h @@ -0,0 +1,20 @@ +#ifndef QUEUE_RCR_H_ +#define QUEUE_RCR_H_ + +#define SIZE 16384 + +struct RCRQueue { + //Size is a power of 2 + void * elements[SIZE]; + unsigned int head; + unsigned int tail; + unsigned int size; +}; + +int enqueueRCRQueue(void * ptr); +void * dequeueRCRQueue(); +void resetRCRQueue(); +int isEmptyRCRQueue(); +int getSizeRCRQueue(); + +#endif