ae8f197cf3fcefd7aacdf0208a1d026c14a5c4d0
[IRC.git] / Robust / src / Runtime / oooJava / Queue_RCR.c
1 #include "Queue_RCR.h"
2 #include "stdlib.h"
3 #include "stdio.h"
4
5 __thread struct RCRQueue myRCRQueue;
6
7 void resetRCRQueue() {
8   myRCRQueue.head = 0;
9   myRCRQueue.tail = 0;
10 }
11
12 //0 would mean sucess
13 //1 would mean fail
14 //since if we reach SIZE, we will stop operation, it doesn't matter
15 //that we overwrite the element in the queue
16 int enqueueRCRQueue(void * ptr) {
17   unsigned int head=myRCRQueue.head+1;
18   if (head&SIZE)
19     head=0;
20
21   if (head==myRCRQueue.tail)
22     return 1;
23   
24   myRCRQueue.elements[head] = ptr;
25   myRCRQueue.head=head;
26   return 0;
27 }
28
29 void * dequeueRCRQueue() {
30   if(myRCRQueue.head==myRCRQueue.tail)
31     return NULL;
32   unsigned int tail=myRCRQueue.tail;
33   void * ptr = myRCRQueue.elements[tail];
34   tail++;
35   if(tail & SIZE)
36     tail =  0;
37   myRCRQueue.tail=tail;
38   return ptr;
39 }
40
41 int isEmptyRCRQueue() {
42   return myRCRQueue.head=myRCRQueue.tail;
43 }
44
45