Shared data structure to process prefetch requests
authoradash <adash>
Tue, 10 Jul 2007 01:39:15 +0000 (01:39 +0000)
committeradash <adash>
Tue, 10 Jul 2007 01:39:15 +0000 (01:39 +0000)
Robust/src/Runtime/DSTM/interface/Makefile
Robust/src/Runtime/DSTM/interface/queue.c [new file with mode: 0644]
Robust/src/Runtime/DSTM/interface/queue.h [new file with mode: 0644]

index f01dcef96860aab1606d8986faa42c4e76db0e43..7f38b40b10a4c1da4f537f1f5d6d0ba0de15b0b8 100644 (file)
@@ -1,22 +1,22 @@
 d-3:
-       gcc -dr -lpthread -g -o d-3 trans.c testd-3.c mlookup.c clookup.c llookup.c dstm.c objstr.c dstmserver.c plookup.c ip.c
+       gcc -dr -lpthread -g -o d-3 trans.c testd-3.c mlookup.c clookup.c llookup.c dstm.c objstr.c dstmserver.c plookup.c ip.c queue.c
 
 demsky:
-       gcc -DDEBUG -lpthread -g -o demsky dstmserver.c testserver.c plookup.c mlookup.c clookup.c llookup.c dstm.c objstr.c trans.c ip.c
+       gcc -DDEBUG -lpthread -g -o demsky dstmserver.c testserver.c plookup.c mlookup.c clookup.c llookup.c dstm.c objstr.c trans.c ip.c queue.c
 
 d-4:
-       gcc -lpthread -g -o d-4 trans.c testd-4.c mlookup.c clookup.c llookup.c dstm.c objstr.c dstmserver.c plookup.c ip.c
+       gcc -lpthread -g -o d-4 trans.c testd-4.c mlookup.c clookup.c llookup.c dstm.c objstr.c dstmserver.c plookup.c ip.c queue.c
 
 all:
-       gcc -lpthread -g -o d-3 trans.c testd-3.c mlookup.c clookup.c llookup.c dstm.c objstr.c dstmserver.c plookup.c ip.c
-       gcc -lpthread -g -o demsky dstmserver.c testserver.c plookup.c mlookup.c clookup.c llookup.c dstm.c objstr.c trans.c ip.c
-       gcc -lpthread -g -o d-4 trans.c testd-4.c mlookup.c clookup.c llookup.c dstm.c objstr.c dstmserver.c plookup.c ip.c
+       gcc -lpthread -g -o d-3 trans.c testd-3.c mlookup.c clookup.c llookup.c dstm.c objstr.c dstmserver.c plookup.c ip.c queue.c
+       gcc -lpthread -g -o demsky dstmserver.c testserver.c plookup.c mlookup.c clookup.c llookup.c dstm.c objstr.c trans.c ip.c queue.c
+       gcc -lpthread -g -o d-4 trans.c testd-4.c mlookup.c clookup.c llookup.c dstm.c objstr.c dstmserver.c plookup.c ip.c queue.c
 
 
 mac:
-       gcc -DMAC -lpthread -g -o d-3 trans.c testd-3.c mlookup.c clookup.c llookup.c dstm.c objstr.c dstmserver.c plookup.c ip.c
-       gcc -DMAC -lpthread -g -o demsky dstmserver.c testserver.c plookup.c mlookup.c clookup.c llookup.c dstm.c objstr.c trans.c ip.c
-       gcc -DMAC -lpthread -g -o d-4 trans.c testd-4.c mlookup.c clookup.c llookup.c dstm.c objstr.c dstmserver.c plookup.c ip.c
+       gcc -DMAC -lpthread -g -o d-3 trans.c testd-3.c mlookup.c clookup.c llookup.c dstm.c objstr.c dstmserver.c plookup.c ip.c queue.c
+       gcc -DMAC -lpthread -g -o demsky dstmserver.c testserver.c plookup.c mlookup.c clookup.c llookup.c dstm.c objstr.c trans.c ip.c queue.c
+       gcc -DMAC -lpthread -g -o d-4 trans.c testd-4.c mlookup.c clookup.c llookup.c dstm.c objstr.c dstmserver.c plookup.c ip.c queue.c
 
 clean:
        rm -rf d-3 d-4 demsky
diff --git a/Robust/src/Runtime/DSTM/interface/queue.c b/Robust/src/Runtime/DSTM/interface/queue.c
new file mode 100644 (file)
index 0000000..fc12eaa
--- /dev/null
@@ -0,0 +1,83 @@
+#include "queue.h"
+
+prefetchthreadqueue_t queue; //Global shared prefetch queue
+
+void queueInsert(int *array) {
+       pthread_mutex_lock(&queue.qlock);
+       queue.rear = queue.rear % ARRAY_SIZE;
+       if(queue.front == queue.rear && queue.buffer[queue.front] != NULL) {
+               printf("The Circular Queue is Full : OVERFLOW\n");
+               pthread_mutex_unlock(&queue.qlock);
+               return;
+       } else {
+               queue.buffer[queue.rear] = array;
+               queue.rear++;
+       }
+       pthread_mutex_unlock(&queue.qlock);
+}
+
+int *queueDelete() {
+       int *i; 
+       i = NULL;
+       pthread_mutex_lock(&queue.qlock);
+       if(queue.front == queue.rear && queue.buffer[queue.front] == NULL) {
+               printf("The Circular Queue is Empty : UNDERFLOW\n");
+               pthread_mutex_unlock(&queue.qlock);
+               return NULL;
+       } else {
+               i = queue.buffer[queue.front];
+               queue.buffer[queue.front] = NULL;
+               queue.front++;
+               queue.front = queue.front % ARRAY_SIZE;
+               pthread_mutex_unlock(&queue.qlock);
+               return i;
+       }
+}
+
+void queueInit() {
+       int i;
+       queue.front = 0;
+       queue.rear = 0;
+       for(i = 0; i< ARRAY_SIZE; i++) 
+               queue.buffer[i] = NULL;
+       /* Initialize the pthread_mutex variable */
+       pthread_mutex_init(&queue.qlock, NULL);
+}
+
+/* For testing purposes */
+#if 0
+main() {
+       int *d; 
+       queueIsEmpty();
+       int a[] = {5, 2, 8, -1};
+       int b[] = {11, 8, 4, 19, -1};
+       int c[] = {16, 8, 4, -1};
+       printf("Front = %d, Rear = %d\n",queue.front, queue.rear);
+       d = queueDelete();
+       printf("Front = %d, Rear = %d\n",queue.front, queue.rear);
+       queueInsert(a);
+       printf("Enqueued ptr is %x\n", a);
+       printf("1st Insert Front = %d, Rear = %d\n",queue.front, queue.rear);
+       queueInsert(b);
+       printf("Enqueued ptr is %x\n", b);
+       printf("2nd Insert Front = %d, Rear = %d\n",queue.front, queue.rear);
+       queueInsert(c);
+       printf("3rd Insert Front = %d, Rear = %d\n",queue.front, queue.rear);
+       d = queueDelete();
+       printf("Dequeued ptr is %x\n", d);
+       printf("After 1st del Front = %d, Rear = %d\n",queue.front, queue.rear);
+       queueInsert(c);
+       printf("Enqueued ptr is %x\n", c);
+       printf("After 4th insert Front = %d, Rear = %d\n",queue.front, queue.rear);
+       d = queueDelete();
+       printf("Dequeued ptr is %x\n", d);
+       printf("After 2nd del Front = %d, Rear = %d\n",queue.front, queue.rear);
+       d = queueDelete();
+       printf("Dequeued ptr is %x\n", d);
+       printf("After 3rd del Front = %d, Rear = %d\n",queue.front, queue.rear);
+       d = queueDelete();
+       printf("Dequeued ptr is %x\n", d);
+       printf("After 4th del Front = %d, Rear = %d\n",queue.front, queue.rear);
+}
+
+#endif
diff --git a/Robust/src/Runtime/DSTM/interface/queue.h b/Robust/src/Runtime/DSTM/interface/queue.h
new file mode 100644 (file)
index 0000000..9ad5df4
--- /dev/null
@@ -0,0 +1,22 @@
+#ifndef _QUEUE_H_
+#define _QUEUE_H_
+
+#include<stdio.h>
+#include<stdlib.h>
+#include<pthread.h>
+
+#define ARRAY_SIZE 20
+
+// DS that contains information to be shared between threads.
+typedef struct prefetchthreadqueue {
+       int *buffer[ARRAY_SIZE];
+       int front;
+       int rear;
+       pthread_mutex_t qlock;
+} prefetchthreadqueue_t;
+
+void queueInsert(int *);
+int *queueDelete();
+void queueInit(); //Initializes the queue and qlock mutex 
+
+#endif