Fix tabbing.... Please fix your editors so they do tabbing correctly!!! (Spaces...
[IRC.git] / Robust / src / Runtime / DSTM / interface / abortreaders.c
index a71aae2d8f37ba57dae47457b4e145135b1e5ea9..1db842096414cecbccd9d2672278b2fa5ca5d21c 100644 (file)
@@ -11,7 +11,7 @@ void initreaderlist() {
   freelist=NULL;
 }
 
-void addtransaction(unsigned int oid, struct transrecord * trans) {
+void addtransaction(unsigned int oid) {
   struct readerlist * rl;
   int i;
   if (pthread_mutex_trylock(&aborttablelock)!=0)
@@ -25,7 +25,7 @@ void addtransaction(unsigned int oid, struct transrecord * trans) {
       freelist=rl->next;
       memset(rl,0, sizeof(struct readerlist));
     }
-    chashInsert(rl, oid, rl);
+    chashInsert(aborttable, oid, rl);
   }
   while(rl->numreaders==READERSIZE) {
     if (rl->next!=NULL)
@@ -36,9 +36,9 @@ void addtransaction(unsigned int oid, struct transrecord * trans) {
     }
   }
   rl->numreaders++;
-  for(i=0;i<READERSIZE;i++) {
+  for(i=0; i<READERSIZE; i++) {
     if (rl->array[i]==NULL) {
-      rl->array[i]=trans;
+      rl->array[i]=&t_abort;
       pthread_mutex_unlock(&aborttablelock);
       return;
     }
@@ -50,17 +50,20 @@ void addtransaction(unsigned int oid, struct transrecord * trans) {
 void removetransaction(unsigned int oidarray[], unsigned int numoids) {
   int i,j;
   pthread_mutex_lock(&aborttablelock);
-  for(i=0;i<numoids;i++) {
+  for(i=0; i<numoids; i++) {
     unsigned int oid=oidarray[i];
-    struct readerlist *rl=chashRemove2(table, oid);
+    struct readerlist *rl=chashRemove2(aborttable, oid);
     struct readerlist *tmp;
+    if (rl==NULL)
+      continue;
     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
+      int count=rl->numreaders;
+      int j;
+      for(j=0; count; j++) {
+       int *t_abort=rl->array[j];
+       if (t_abort!=NULL) {
+         *t_abort=1; //It's okay to set our own abort flag...it is
+         //too late to abort us
          count--;
        }
       }
@@ -73,23 +76,103 @@ void removetransaction(unsigned int oidarray[], unsigned int numoids) {
   pthread_mutex_unlock(&aborttablelock);
 }
 
-void removeaborttransaction(unsigned int oidarray[], unsigned int numoids, struct transrecord * trans) {
+void removethisreadtransaction(unsigned char* oidverread, unsigned int numoids) {
   int i,j;
   pthread_mutex_lock(&aborttablelock);
-  for(i=0;i<numoids;i++) {
+  for(i=0; i<numoids; i++) {
+    unsigned int oid=*((unsigned int *)oidverread);
+    struct readerlist * rl=chashSearch(aborttable, oid);
+    struct readerlist *first=rl;
+    oidverread+=(sizeof(unsigned int)+sizeof(unsigned short));
+    while(rl!=NULL) {
+      for(j=0; j<READERSIZE; j++) {
+       if (rl->array[j]==&t_abort) {
+         rl->array[j]=NULL;
+         if ((--rl->numreaders)==0) {
+           if (first==rl) {
+             chashRemove2(aborttable, oid);
+             if (rl->next!=NULL)
+               chashInsert(aborttable, 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);
+}
+
+void removetransactionhash() {
+  chashlistnode_t *ptr=c_table;
+  int i,j;
+  pthread_mutex_lock(&aborttablelock);
+  for(i=0; i<c_size; i++) {
+    chashlistnode_t *curr=&ptr[i];
+    do {
+      unsigned int oid=curr->key;
+      if (oid==0)
+       break;
+      struct readerlist * rl=chashSearch(aborttable, oid);
+      struct readerlist *first=rl;
+      while(rl!=NULL) {
+       for(j=0; j<READERSIZE; j++) {
+         if (rl->array[j]==&t_abort) {
+           rl->array[j]=NULL;
+           if ((--rl->numreaders)==0) {
+             if (first==rl) {
+               chashRemove2(aborttable, oid);
+               if (rl->next!=NULL)
+                 chashInsert(aborttable, 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:
+      curr=curr->next;
+    } while(curr!=NULL);
+  }
+  pthread_mutex_unlock(&aborttablelock);
+}
+
+
+void removethistransaction(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=chashSearch(aborttable, oid);
-    
+
     struct readerlist *first=rl;
-    while(1) {
-      for(j=0;j<READERSIZE;j++) {
-       if (rl->array[j]==trans) {
+    while(rl!=NULL) {
+      for(j=0; j<READERSIZE; j++) {
+       if (rl->array[j]==&t_abort) {
          rl->array[j]=NULL;
          if ((--rl->numreaders)==0) {
            if (first==rl) {
-             chashRemove2(table, oid);
-             if (rl->next!=NULL) 
-               chashInsert(table, oid, rl->next);
+             chashRemove2(aborttable, oid);
+             if (rl->next!=NULL)
+               chashInsert(aborttable, oid, rl->next);
              rl->next=freelist;
              freelist=rl;
            } else {
@@ -104,7 +187,8 @@ void removeaborttransaction(unsigned int oidarray[], unsigned int numoids, struc
       first=rl;
       rl=rl->next;
     }
-  nextitem:
+nextitem:
+    ;
   }
   pthread_mutex_unlock(&aborttablelock);
 }