Fix tabbing.... Please fix your editors so they do tabbing correctly!!! (Spaces...
[IRC.git] / Robust / src / Runtime / DSTM / interface / abortreaders.c
index 73e9033abf4eb3047228c6b6a8c93171ca1904bb..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,23 @@ void removetransaction(unsigned int oidarray[], unsigned int numoids) {
   pthread_mutex_unlock(&aborttablelock);
 }
 
-void removethisreadtransaction(unsigned char* oidverread, 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(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,17 +107,17 @@ void removethisreadtransaction(unsigned char* oidverread, unsigned int numoids,
       first=rl;
       rl=rl->next;
     }
-  nextitem:
+nextitem:
+    ;
   }
   pthread_mutex_unlock(&aborttablelock);
 }
 
-void removetransactionhash(chashtable_t *table, struct transrecord *trans) {
-  chashlistnode_t *ptr=table->table;
-  unsigned int size=table->size;
+void removetransactionhash() {
+  chashlistnode_t *ptr=c_table;
   int i,j;
   pthread_mutex_lock(&aborttablelock);
-  for(i=0;i<size;i++) {
+  for(i=0; i<c_size; i++) {
     chashlistnode_t *curr=&ptr[i];
     do {
       unsigned int oid=curr->key;
@@ -122,15 +125,15 @@ void removetransactionhash(chashtable_t *table, struct transrecord *trans) {
        break;
       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 {
@@ -145,7 +148,7 @@ void removetransactionhash(chashtable_t *table, struct transrecord *trans) {
        first=rl;
        rl=rl->next;
       }
-    nextitem:
+nextitem:
       curr=curr->next;
     } while(curr!=NULL);
   }
@@ -153,23 +156,23 @@ void removetransactionhash(chashtable_t *table, struct transrecord *trans) {
 }
 
 
-void removethistransaction(unsigned int oidarray[], unsigned int numoids, struct transrecord * trans) {
+void removethistransaction(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=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 {
@@ -184,7 +187,8 @@ void removethistransaction(unsigned int oidarray[], unsigned int numoids, struct
       first=rl;
       rl=rl->next;
     }
-  nextitem:
+nextitem:
+    ;
   }
   pthread_mutex_unlock(&aborttablelock);
 }