__thread struct RCRQueue myRCRQueue;
-void resetRCRQueue()
-{
+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 & SIZE)
- myRCRQueue.head = 0;
-
- return myRCRQueue.size++ == SIZE;
+int enqueueRCRQueue(void * ptr) {
+ unsigned int head=myRCRQueue.head+1;
+ if (head&SIZE)
+ head=0;
+
+ if (head==myRCRQueue.tail)
+ return 1;
+
+ myRCRQueue.elements[head] = ptr;
+ myRCRQueue.head=head;
+ return 0;
}
-void * dequeueRCRQueue()
-{
- if(myRCRQueue.size) {
- void * ptr = myRCRQueue.elements[myRCRQueue.tail++];
-
- if(myRCRQueue.tail & SIZE)
- myRCRQueue.tail = 0;
-
-
- myRCRQueue.size--;
- return ptr;
- } else
+void * dequeueRCRQueue() {
+ if(myRCRQueue.head==myRCRQueue.tail)
return NULL;
+ unsigned int tail=myRCRQueue.tail;
+ void * ptr = myRCRQueue.elements[tail];
+ tail++;
+ if(tail & SIZE)
+ tail = 0;
+ myRXRQueue.tail=tail;
+ return ptr;
}
-int isEmptyRCRQueue()
-{
- return !myRCRQueue.size;
-}
-
-int getSizeRCRQueue()
-{
- return myRCRQueue.size;
+int isEmptyRCRQueue() {
+ return myRCRQueue.head=myRCRQueue.tail;
}
void * elements[SIZE];
unsigned int head;
unsigned int tail;
- unsigned int size;
};
int enqueueRCRQueue(void * ptr);
void resetRCRQueue();
int isEmptyRCRQueue();
int getSizeRCRQueue();
-
#endif
--- /dev/null
+#include "rcr_runtime.h"
+
+void workerTR(void *x) {
+ struct trQueue * queue=(struct trQueue *)x;
+ while(true) {
+
+ }
+}
--- /dev/null
+#ifndef RCR_RUNTIME_H
+#define RCR_RUNTIME_H
+
+extern __thread struct trqueue * TRqueue;
+
+void workerTR(void *);
+
+#endif
--- /dev/null
+#include "trqueue.h"
+#include "stdlib.h"
+#include "stdio.h"
+
+//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
+void enqueueTR(trQueue *q, void * ptr) {
+ unsigned int head=q->head+1;
+ if (head&TRSIZE)
+ head=0;
+
+ while (head==q->tail)
+ sched_yield();
+
+ q->elements[head] = ptr;
+ BARRIER();
+ q->head=head;
+ return 0;
+}
+
+void * dequeueTR(trQueue *q) {
+ unsigned int tail=q->tail;
+ if(q->head==tail)
+ return NULL;
+
+ void * ptr = q->elements[tail];
+ tail++;
+ if(tail & TRSIZE)
+ tail = 0;
+ q->tail=tail;
+ return ptr;
+}
+
+struct trQueue * allocTR() {
+ struct trQueue *ptr=malloc(sizeof(struct trQueue));
+ ptr->head=0;
+ ptr->tail=0;
+ return ptr;
+}
+
--- /dev/null
+#ifndef TRQUEUE_H_
+#define TRQUEUE_H_
+
+//NOTE: SIZE MUST BE A POWER OF TWO;
+//SIZE is used as mask to check overflow
+#define SIZE 16384
+
+struct trQueue {
+ void * elements[SIZE];
+ volatile unsigned int head;
+ char buffer[60];//buffer us to the next cache line
+ volatile unsigned int tail;
+};
+
+void enqueueTR(struct trQueue *, void * ptr);
+void * dequeueTR(struct trQueue *);
+struct trQueue * allocTR();
+#endif