changes
[IRC.git] / Robust / src / Runtime / oooJava / trqueue.c
1 #include "trqueue.h"
2 #include "stdlib.h"
3 #include "stdio.h"
4
5 //0 would mean sucess
6 //1 would mean fail
7 //since if we reach SIZE, we will stop operation, it doesn't matter
8 //that we overwrite the element in the queue
9 void enqueueTR(trQueue *q, void * ptr) {
10   unsigned int head=q->head+1;
11   if (head&TRSIZE)
12     head=0;
13
14   while (head==q->tail)
15     sched_yield();
16   
17   q->elements[head] = ptr;
18   BARRIER();
19   q->head=head;
20   return 0;
21 }
22
23 void * dequeueTR(trQueue *q) {
24   unsigned int tail=q->tail;
25   if(q->head==tail)
26     return NULL;
27
28   void * ptr = q->elements[tail];
29   tail++;
30   if(tail & TRSIZE)
31     tail =  0;
32   q->tail=tail;
33   return ptr;
34 }
35
36 struct trQueue * allocTR() {
37   struct trQueue *ptr=malloc(sizeof(struct trQueue));
38   ptr->head=0;
39   ptr->tail=0;
40   return ptr;
41 }
42