cleaned up code
authorbdemsky <bdemsky>
Thu, 29 Jan 2009 22:29:42 +0000 (22:29 +0000)
committerbdemsky <bdemsky>
Thu, 29 Jan 2009 22:29:42 +0000 (22:29 +0000)
fixed random bugs in the search for the halting bug
defined pure attribute for transRead method...see if gcc can help us
more now

Robust/src/Runtime/DSTM/interface/dstm.h
Robust/src/Runtime/DSTM/interface/dstmserver.c
Robust/src/Runtime/DSTM/interface/trans.c

index 05dc2be65d5c810693052a43d816b84d87ba80bb..5532d6bc7641009c36e61c3d6414395dd94daa87 100644 (file)
@@ -279,7 +279,7 @@ void mapObjMethod(unsigned short);
 
 void randomdelay();
 transrecord_t *transStart();
-objheader_t *transRead(transrecord_t *, unsigned int);
+__attribute__((pure)) objheader_t *transRead(transrecord_t *, unsigned int);
 objheader_t *transCreateObj(transrecord_t *, unsigned int); //returns oid header
 int transCommit(transrecord_t *record); //return 0 if successful
 void *transRequest(void *);     //the C routine that the thread will execute when TRANS_REQUEST begins
index 79351126fac1d48a0a1fc556d223a69ced07e067..f2e5f16198d97bee21dcb6ddf50548e7bdad77c6 100644 (file)
@@ -464,8 +464,7 @@ char handleTransReq(fixed_data_t *fixed, trans_commit_data_t *transinfo, unsigne
                                &v_matchnolock, &v_matchlock, &v_nomatch, &numBytes, &control, oid, version);
     } else {  //Objs modified
       if(i == fixed->numread) {
-       oidlocked[objlocked] = -1;
-       objlocked++;
+       oidlocked[objlocked++] = -1;
       }
       int tmpsize;
       headptr = (objheader_t *) ptr;
@@ -563,8 +562,7 @@ void getCommitCountForObjMod(unsigned int *oidnotfound, unsigned int *oidlocked,
        //printf("%s() oid = %d, type = %d\t", __func__, OID(mobj), TYPE((objheader_t *)mobj));
       }
       //Keep track of oid locked
-      oidlocked[*objlocked] = OID(((objheader_t *)mobj));
-      (*objlocked)++;
+      oidlocked[(*objlocked)++] = OID(((objheader_t *)mobj));
     } else {  //we are locked
       if (version == ((objheader_t *)mobj)->version) {     /* Check if versions match */
        (*v_matchlock)++;
@@ -600,8 +598,7 @@ void getCommitCountForObjRead(unsigned int *oidnotfound, unsigned int *oidlocked
        (*v_matchnolock)++;
       } else { /* If versions don't match ...HARD ABORT */
        (*v_nomatch)++;
-       oidvernotmatch[*objvernotmatch] = oid;
-       (*objvernotmatch)++;
+       oidvernotmatch[(*objvernotmatch)++] = oid;
        int size;
        GETSIZE(size, mobj);
        size += sizeof(objheader_t);
@@ -611,8 +608,7 @@ void getCommitCountForObjRead(unsigned int *oidnotfound, unsigned int *oidlocked
        //printf("%s() oid = %d, type = %d\t", __func__, OID(mobj), TYPE((objheader_t *)mobj));
       }
       //Keep track of oid locked
-      oidlocked[*objlocked] = OID(((objheader_t *)mobj));
-      (*objlocked)++;
+      oidlocked[(*objlocked)++] = OID(((objheader_t *)mobj));
     } else { /* Some other transaction has aquired a write lock on this object */
       if (version == ((objheader_t *)mobj)->version) { /* Check if versions match */
        (*v_matchlock)++;
@@ -689,7 +685,15 @@ int transCommitProcess(void *modptr, unsigned int *oidmod, unsigned int *oidlock
       return 1;
     }
     GETSIZE(tmpsize,header);
-    memcpy((char*)header + sizeof(objheader_t), ((char *)modptr + sizeof(objheader_t) + offset), tmpsize);
+    
+    {
+      struct ___Object___ *dst=(struct ___Object___*)((char*)header+sizeof(objheader_t));
+      struct ___Object___ *src=(struct ___Object___*)((char*)modptr+sizeof(objheader_t)+offset);
+      dst->type=src->type;
+      dst->___cachedCode___=src->___cachedCode___;
+      dst->___cachedHash___=src->___cachedHash___;
+      memcpy(&dst[1], &src[1], tmpsize-sizeof(struct ___Object___));
+    }
     header->version += 1;
     /* If threads are waiting on this object to be updated, notify them */
     if(header->notifylist != NULL) {
index 27e61f7ebe1d5a55584534b6417b428aad8eef81..bfa25fbfa0d818c1d1849a5381b9b9ee365e341d 100644 (file)
@@ -354,7 +354,7 @@ INLINE void * chashSearchI(chashtable_t *table, unsigned int key) {
 
 /* This function finds the location of the objects involved in a transaction
  * and returns the pointer to the object if found in a remote location */
-objheader_t *transRead(transrecord_t *record, unsigned int oid) {
+__attribute__((pure)) objheader_t *transRead(transrecord_t *record, unsigned int oid) {
   unsigned int machinenumber;
   objheader_t *tmp, *objheader;
   objheader_t *objcopy;
@@ -818,8 +818,7 @@ void handleLocalReq(trans_req_data_t *tdata, trans_commit_data_t *transinfo, tra
       commitCountForObjRead(getReplyCtrl, oidnotfound, oidlocked, &numoidnotfound, &numoidlocked, &v_nomatch, &v_matchlock, &v_matchnolock, oid, version);
     } else { // Objects Modified
       if(i == tdata->f.numread) {
-       oidlocked[numoidlocked] = -1;
-       numoidlocked++;
+       oidlocked[numoidlocked++] = -1;
       }
       int tmpsize;
       objheader_t *headptr;
@@ -875,6 +874,8 @@ void doLocalProcess(char finalResponse, trans_req_data_t *tdata, trans_commit_da
       fflush(stdout);
       return;
     }
+  } else {
+    printf("ERROR...No Decision\n");
   }
 
   /* Free memory */
@@ -985,16 +986,14 @@ void commitCountForObjMod(char *getReplyCtrl, unsigned int *oidnotfound, unsigne
       if (version == ((objheader_t *)mobj)->version) {      /* match versions */
        (*v_matchnolock)++;
        //Keep track of what is locked
-       oidlocked[*numoidlocked] = OID(((objheader_t *)mobj));
-       (*numoidlocked)++;
+       oidlocked[(*numoidlocked)++] = OID(((objheader_t *)mobj));
       } else { /* If versions don't match ...HARD ABORT */
        (*v_nomatch)++;
        /* Send TRANS_DISAGREE to Coordinator */
        *getReplyCtrl = TRANS_DISAGREE;
 
        //Keep track of what is locked
-       oidlocked[*numoidlocked] = OID(((objheader_t *)mobj));
-       (*numoidlocked)++;
+       oidlocked[(*numoidlocked)++] = OID(((objheader_t *)mobj));
        //printf("%s() oid = %d, type = %d\t", __func__, OID(mobj), TYPE((objheader_t *)mobj));
        return;
       }
@@ -1028,15 +1027,13 @@ void commitCountForObjRead(char *getReplyCtrl, unsigned int *oidnotfound, unsign
       if (version == ((objheader_t *)mobj)->version) {      /* If locked then match versions */
        (*v_matchnolock)++;
        //Keep track of what is locked
-       oidlocked[*numoidlocked] = OID(((objheader_t *)mobj));
-       (*numoidlocked)++;
+       oidlocked[(*numoidlocked)++] = OID(((objheader_t *)mobj));
       } else { /* If versions don't match ...HARD ABORT */
        (*v_nomatch)++;
        /* Send TRANS_DISAGREE to Coordinator */
        *getReplyCtrl = TRANS_DISAGREE;
        //Keep track of what is locked
-       oidlocked[*numoidlocked] = OID(((objheader_t *)mobj));
-       (*numoidlocked)++;
+       oidlocked[(*numoidlocked)++] = OID(((objheader_t *)mobj));
        //printf("%s() oid = %d, type = %d\t", __func__, OID(mobj), TYPE((objheader_t *)mobj));
        return;
       }
@@ -1110,7 +1107,15 @@ int transComProcess(trans_req_data_t *tdata, trans_commit_data_t *transinfo, tra
     }
     GETSIZE(tmpsize, header);
     char *tmptcptr = (char *) tcptr;
-    memcpy((char*)header+sizeof(objheader_t), (char *)tmptcptr+ sizeof(objheader_t), tmpsize);
+    {
+      struct ___Object___ *dst=(struct ___Object___*)((char*)header+sizeof(objheader_t));
+      struct ___Object___ *src=(struct ___Object___*)((char*)tmptcptr+sizeof(objheader_t));
+      dst->___cachedCode___=src->___cachedCode___;
+      dst->___cachedHash___=src->___cachedHash___;
+
+      memcpy(&dst[1], &src[1], tmpsize-sizeof(struct ___Object___));
+    }
+
     header->version += 1;
     if(header->notifylist != NULL) {
       notifyAll(&header->notifylist, OID(header), header->version);
@@ -1648,29 +1653,21 @@ int reqNotify(unsigned int *oidarry, unsigned short *versionarry, unsigned int n
     *((unsigned int *)(&msg[1])) = numoid;
     /* Send array of oids  */
     size = sizeof(unsigned int);
-    {
-      i = 0;
-      while(i < numoid) {
-       oid = oidarry[i];
-       *((unsigned int *)(&msg[1] + size)) = oid;
-       size += sizeof(unsigned int);
-       i++;
-      }
+
+    for(i = 0;i < numoid; i++) {
+      oid = oidarry[i];
+      *((unsigned int *)(&msg[1] + size)) = oid;
+      size += sizeof(unsigned int);
     }
 
     /* Send array of version  */
-    {
-      i = 0;
-      while(i < numoid) {
-       version = versionarry[i];
-       *((unsigned short *)(&msg[1] + size)) = version;
-       size += sizeof(unsigned short);
-       i++;
-      }
+    for(i = 0;i < numoid; i++) {
+      version = versionarry[i];
+      *((unsigned short *)(&msg[1] + size)) = version;
+      size += sizeof(unsigned short);
     }
 
-    *((unsigned int *)(&msg[1] + size)) = myIpAddr;
-    size += sizeof(unsigned int);
+    *((unsigned int *)(&msg[1] + size)) = myIpAddr; size += sizeof(unsigned int);
     *((unsigned int *)(&msg[1] + size)) = threadid;
     pthread_mutex_lock(&(ndata->threadnotify));
     size = 1 + numoid * (sizeof(unsigned int) + sizeof(unsigned short)) + 3 * sizeof(unsigned int);
@@ -1716,7 +1713,9 @@ void threadNotify(unsigned int oid, unsigned short version, unsigned int tid) {
          prehashRemove(oid);
        }
 #endif
+       pthread_mutex_lock(&(ndata->threadnotify));
        pthread_cond_signal(&(ndata->threadcond));
+       pthread_mutex_unlock(&(ndata->threadnotify));
       }
     }
   }