more changes towards new version of oooJava
[IRC.git] / Robust / src / Runtime / oooJava / trqueue.c
1 #include "trqueue.h"
2 #include "stdlib.h"
3 #include "stdio.h"
4 #include "mlp_lock.h"
5
6 //0 would mean sucess
7 //1 would mean fail
8 //since if we reach SIZE, we will stop operation, it doesn't matter
9 //that we overwrite the element in the queue
10 void enqueueTR(struct trQueue *q, void * ptr) {
11   unsigned int head=q->head+1;
12   if (head&TRSIZE)
13     head=0;
14
15   while (head==q->tail)
16     sched_yield();
17   
18   q->elements[head] = ptr;
19   BARRIER();
20   q->head=head;
21 }
22
23 void * dequeueTR(struct 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