X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=Robust%2Fsrc%2FRuntime%2FDSTM%2Finterface%2Fqueue.c;h=c892a030266b67d02f095c6995e1139c7c7e2739;hb=cdcf09c40af1419fa42932aae249cb79b69b5daf;hp=507cf65811da40fbf2619fead2e6338e6f098d90;hpb=8072bda4c1c7c5c9dd3027c40e69bf1dc9aa9bc5;p=IRC.git diff --git a/Robust/src/Runtime/DSTM/interface/queue.c b/Robust/src/Runtime/DSTM/interface/queue.c deleted file mode 100644 index 507cf658..00000000 --- a/Robust/src/Runtime/DSTM/interface/queue.c +++ /dev/null @@ -1,85 +0,0 @@ -#include "queue.h" - -volatile int headoffset, tailoffset; -char * memory; -pthread_mutex_t qlock; -pthread_mutexattr_t qlockattr; -pthread_cond_t qcond; - - -#define QSIZE 1000000 //1 MB - -void queueInit(void) { - /* Intitialize primary queue */ - headoffset=0; - tailoffset=0; - 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); - pthread_cond_init(&qcond, NULL); -} - -void * getmemory(int size) { - int tmpoffset=headoffset+size+sizeof(int); - if (tmpoffset>QSIZE) { - //Wait for tail to go past end - tmpoffset=size+sizeof(int); - if (headoffsetQSIZE) { - headoffset=size+sizeof(int); - } else - headoffset=tmpoffset; - pthread_cond_signal(&qcond);//wake the other thread up -} - -void * gettail() { - while(tailoffset==headoffset) { - //Sleep - pthread_mutex_lock(&qlock); - if (tailoffset==headoffset) - pthread_cond_wait(&qcond, &qlock); - pthread_mutex_unlock(&qlock); - } - if (*((int *)(memory+tailoffset))==-1) { - tailoffset=0;//do loop - } - - return memory+tailoffset+sizeof(int); -} - -void inctail() { - int tmpoffset=tailoffset+*((int *)(memory+tailoffset)); - if (tmpoffset>QSIZE) - tailoffset=0; - else - tailoffset=tmpoffset; -} - -void predealloc() { - free(memory); -} -