helpful progress reporting
[IRC.git] / Robust / src / Runtime / DSTM / interface / queue.c
index 9f2eb419b9ff96791c3e820838a70589182ce72e..c892a030266b67d02f095c6995e1139c7c7e2739 100644 (file)
@@ -6,14 +6,13 @@ pthread_mutex_t qlock;
 pthread_mutexattr_t qlockattr;
 pthread_cond_t qcond;
 
-
-#define QSIZE 1000000 //1 MB
+#define QSIZE 2048 //2 KB
 
 void queueInit(void) {
   /* Intitialize primary queue */
   headoffset=0;
   tailoffset=0;
-  memory=malloc(QSIZE+sizeof(int));//leave space for -1
+  memory=malloc(QSIZE+sizeof(int)); //leave space for -1
   pthread_mutexattr_init(&qlockattr);
   pthread_mutexattr_settype(&qlockattr, PTHREAD_MUTEX_RECURSIVE_NP);
   pthread_mutex_init(&qlock, &qlockattr);
@@ -25,17 +24,23 @@ void * getmemory(int size) {
   if (tmpoffset>QSIZE) {
     //Wait for tail to go past end
     tmpoffset=size+sizeof(int);
-    while(headoffset<tailoffset)
-      ;
+    if (headoffset<tailoffset) {
+      pthread_cond_signal(&qcond); //wake the other thread up
+      return NULL;
+    }
     //Wait for tail to go past new start
-    while(tailoffset<=tmpoffset)
-      ;
-    *((int *)(memory+headoffset))=-1;//safe because we left space
+    if (tailoffset<=tmpoffset) {
+      pthread_cond_signal(&qcond); //wake the other thread up
+      return NULL;
+    }
+    *((int *)(memory+headoffset))=-1; //safe because we left space
     *((int*)memory)=size+sizeof(int);
     return memory+sizeof(int);
   } else {
-    while(headoffset<tailoffset&&tailoffset<=tmpoffset)
-      ;
+    if (headoffset<tailoffset&&tailoffset<=tmpoffset) {
+      pthread_cond_signal(&qcond); //wake the other thread up
+      return NULL;
+    }
     *((int*)(memory+headoffset))=size+sizeof(int);
     return memory+headoffset+sizeof(int);
   }
@@ -47,7 +52,7 @@ void movehead(int size) {
     headoffset=size+sizeof(int);
   } else
     headoffset=tmpoffset;
-  pthread_cond_signal(&qcond);//wake the other thread up
+  pthread_cond_signal(&qcond); //wake the other thread up
 }
 
 void * gettail() {
@@ -59,7 +64,7 @@ void * gettail() {
     pthread_mutex_unlock(&qlock);
   }
   if (*((int *)(memory+tailoffset))==-1) {
-    tailoffset=0;//do loop
+    tailoffset=0; //do loop
   }
 
   return memory+tailoffset+sizeof(int);