changes
authorbdemsky <bdemsky>
Fri, 6 Feb 2009 07:49:58 +0000 (07:49 +0000)
committerbdemsky <bdemsky>
Fri, 6 Feb 2009 07:49:58 +0000 (07:49 +0000)
Robust/src/Runtime/DSTM/interface/abortreaders.c [new file with mode: 0644]
Robust/src/Runtime/DSTM/interface/abortreaders.h [new file with mode: 0644]
Robust/src/Runtime/DSTM/interface/clookup.c
Robust/src/Runtime/DSTM/interface/clookup.h
Robust/src/Runtime/DSTM/interface/dstm.h
Robust/src/Runtime/DSTM/interface/trans.c

diff --git a/Robust/src/Runtime/DSTM/interface/abortreaders.c b/Robust/src/Runtime/DSTM/interface/abortreaders.c
new file mode 100644 (file)
index 0000000..a71aae2
--- /dev/null
@@ -0,0 +1,111 @@
+#include "clookup.h"
+#include "abortreaders.h"
+
+chashtable_t * aborttable;
+pthread_mutex_t aborttablelock;
+struct readerlist *freelist;
+
+void initreaderlist() {
+  pthread_mutex_init(&aborttablelock, NULL);
+  aborttable=chashCreate(CHASH_SIZE, CLOADFACTOR);
+  freelist=NULL;
+}
+
+void addtransaction(unsigned int oid, struct transrecord * trans) {
+  struct readerlist * rl;
+  int i;
+  if (pthread_mutex_trylock(&aborttablelock)!=0)
+    return;
+  rl=(struct readerlist *)chashSearch(aborttable, oid);
+  if (rl==NULL) {
+    if (freelist==NULL)
+      rl=calloc(1,sizeof(struct readerlist ));
+    else {
+      rl=freelist;
+      freelist=rl->next;
+      memset(rl,0, sizeof(struct readerlist));
+    }
+    chashInsert(rl, oid, rl);
+  }
+  while(rl->numreaders==READERSIZE) {
+    if (rl->next!=NULL)
+      rl=rl->next;
+    else {
+      rl->next=calloc(1,sizeof(struct readerlist));
+      rl=rl->next;
+    }
+  }
+  rl->numreaders++;
+  for(i=0;i<READERSIZE;i++) {
+    if (rl->array[i]==NULL) {
+      rl->array[i]=trans;
+      pthread_mutex_unlock(&aborttablelock);
+      return;
+    }
+  }
+  pthread_mutex_unlock(&aborttablelock);
+  printf("ERROR in addtransaction\n");
+}
+
+void removetransaction(unsigned int oidarray[], unsigned int numoids) {
+  int i,j;
+  pthread_mutex_lock(&aborttablelock);
+  for(i=0;i<numoids;i++) {
+    unsigned int oid=oidarray[i];
+    struct readerlist *rl=chashRemove2(table, oid);
+    struct readerlist *tmp;
+    do {
+      count=rl->numreaders;
+      for(int j=0;count;j++) {
+       struct transrecord *trans=rl->array[j];
+       if (trans!=NULL) {
+         trans->abort=1;//It's okay to set our own abort flag...it is
+                        //too late to abort us
+         count--;
+       }
+      }
+      tmp=rl;
+      rl=rl->next;
+      tmp->next=freelist;
+      freelist=tmp;
+    } while(rl!=NULL);
+  }
+  pthread_mutex_unlock(&aborttablelock);
+}
+
+void removeaborttransaction(unsigned int oidarray[], unsigned int numoids, struct transrecord * trans) {
+  int i,j;
+  pthread_mutex_lock(&aborttablelock);
+  for(i=0;i<numoids;i++) {
+    unsigned int oid=oidarray[i];
+    struct readerlist * rl=chashSearch(aborttable, oid);
+    
+    struct readerlist *first=rl;
+    while(1) {
+      for(j=0;j<READERSIZE;j++) {
+       if (rl->array[j]==trans) {
+         rl->array[j]=NULL;
+         if ((--rl->numreaders)==0) {
+           if (first==rl) {
+             chashRemove2(table, oid);
+             if (rl->next!=NULL) 
+               chashInsert(table, oid, rl->next);
+             rl->next=freelist;
+             freelist=rl;
+           } else {
+             first->next=rl->next;
+             rl->next=freelist;
+             freelist=rl;
+           }
+         }
+         goto nextitem;
+       }
+      }
+      first=rl;
+      rl=rl->next;
+    }
+  nextitem:
+  }
+  pthread_mutex_unlock(&aborttablelock);
+}
+
diff --git a/Robust/src/Runtime/DSTM/interface/abortreaders.h b/Robust/src/Runtime/DSTM/interface/abortreaders.h
new file mode 100644 (file)
index 0000000..c0115c1
--- /dev/null
@@ -0,0 +1,18 @@
+#ifndef ABORTREADERS_H
+#define ABORTREADERS_H
+#include "dstm.h"
+
+#define READERSIZE 8
+
+struct readerlist {
+  struct transrecord *array[READERSIZE];
+  int numreaders;
+  struct readerlist * next;
+};
+
+void initreaderlist();
+void addtransaction(unsigned int oid, struct transrecord * trans);
+void removetransaction(unsigned int oidarray[], unsigned int numoids);
+void removeaborttransaction(unsigned int oidarray[], unsigned int numoids, struct transrecord * trans);
+
+#endif
index fee16fa73cdc01930b603b1c184734dfa1d0b6f8..33aab6b3d23daea00e9b4da35045156ae8243336 100644 (file)
@@ -82,9 +82,15 @@ INLINE void * chashSearch(chashtable_t *table, unsigned int key) {
 }
 
 unsigned int chashRemove(chashtable_t *table, unsigned int key) {
+  return chashRemove2(table, key)==NULL;
+
+}
+
+void * chashRemove2(chashtable_t *table, unsigned int key) {
   int index;
   chashlistnode_t *curr, *prev;
   chashlistnode_t *ptr, *node;
+  void *value;
 
   ptr = table->table;
   index = chashFunction(table,key);
@@ -95,22 +101,25 @@ unsigned int chashRemove(chashtable_t *table, unsigned int key) {
       table->numelements--;  // Decrement the number of elements in the global hashtable
       if ((curr == &ptr[index]) && (curr->next == NULL)) {  // Delete the first item inside the hashtable with no linked list of chashlistnode_t
        curr->key = 0;
+       value=curr->val;
        curr->val = NULL;
       } else if ((curr == &ptr[index]) && (curr->next != NULL)) { //Delete the first item with a linked list of chashlistnode_t  connected
        curr->key = curr->next->key;
+       value=curr->val;
        curr->val = curr->next->val;
        node = curr->next;
        curr->next = curr->next->next;
        free(node);
       } else {                                          // Regular delete from linked listed
        prev->next = curr->next;
+       value=curr->val;
        free(curr);
       }
-      return 0;
+      return value;
     }
     prev = curr;
   }
-  return 1;
+  return NULL;
 }
 
 unsigned int chashResize(chashtable_t *table, unsigned int newsize) {
index 4a078d2c94375cc1ed66e27251967514ffc9d5b7..fb7a27173c44e447e91e103a2860f80ec0ab0006 100644 (file)
@@ -27,6 +27,7 @@ static unsigned int chashFunction(chashtable_t *table, unsigned int key);
 unsigned int chashInsert(chashtable_t *table, unsigned int key, void *val);
 void *chashSearch(chashtable_t *table, unsigned int key); //returns val, NULL if not found
 unsigned int chashRemove(chashtable_t *table, unsigned int key); //returns -1 if not found
+void * chashRemove2(chashtable_t *table, unsigned int key); //returns -1 if not found
 unsigned int chashResize(chashtable_t *table, unsigned int newsize);
 void chashDelete(chashtable_t *table);
 /* end hash */
index 5532d6bc7641009c36e61c3d6414395dd94daa87..d501be66291c852108d50e5d1a96f02f8e3a02c5 100644 (file)
@@ -165,6 +165,10 @@ typedef struct transrecord {
 #ifdef COMPILER
   struct ___Object___ * revertlist;
 #endif
+#ifdef ABORTREADERS
+  int abort;
+  jmp_buf aborttrans;
+#endif
 } transrecord_t;
 
 // Structure is a shared structure that keeps track of responses from the participants
index bfa25fbfa0d818c1d1849a5381b9b9ee365e341d..0b64b92389e0c14b4963068c1e940c57824270bb 100644 (file)
@@ -395,6 +395,15 @@ __attribute__((pure)) objheader_t *transRead(transrecord_t *record, unsigned int
 #endif
   } else 
   */
+
+#ifdef ABORTREADERS
+  if (trans->abort) {
+    //abort this transaction
+    longjmp(trans->aborttrans,1);
+  } else
+    addtransaction(oid,record);
+#endif
+
   if ((objheader = (objheader_t *) mhashSearch(oid)) != NULL) {
 #ifdef TRANSSTATS
     nmhashSearch++;