add native method for clearing prefetch cache to System.java
[IRC.git] / Robust / src / Runtime / thread.c
index cc1bed7359b632d405ffcbca63ed87d580ccb644..4dc88de3f10ac4a9fa1ff9dd6d6d4f6a35e073eb 100644 (file)
@@ -19,12 +19,12 @@ pthread_cond_t objcond;
 pthread_key_t threadlocks;
 pthread_mutex_t threadnotifylock;
 pthread_cond_t threadnotifycond;
-transrecord_t * trans;
-pthread_key_t oid;
+pthread_key_t oidval;
 
 void threadexit() {
   objheader_t* ptr;
   void *value;
+  transrecord_t * trans;
   unsigned int oidvalue;
 
 #ifdef THREADS
@@ -47,18 +47,19 @@ void threadexit() {
   pthread_mutex_unlock(&gclistlock);
 #ifdef DSTM
   /* Add transaction to check if thread finished for join operation */
-  value = pthread_getspecific(oid);
+  value = pthread_getspecific(oidval);
   oidvalue = *((unsigned int *)value);
   goto transstart;
 transstart:
-  trans = transStart();
-  ptr = transRead(trans, oidvalue);
-  struct ___Thread___ *p = (struct ___Thread___ *) ptr;
-  p->___threadDone___ = 1;
-  while(!transCommit(trans)) {
-         printf("DEBUG-> Trans not committed yet\n");
-         transAbort(trans);
-         goto transstart;
+  {
+    transrecord_t * trans = transStart();
+    ptr = transRead(trans, oidvalue);
+    struct ___Thread___ *p = (struct ___Thread___ *) ptr;
+    p->___threadDone___ = 1;
+    *((unsigned int *)&((struct ___Object___ *) p)->___localcopy___) |=DIRTY;
+    if(transCommit(trans) != 0) {
+      goto transstart;
+    }
   }
 #endif 
   pthread_exit(NULL);
@@ -124,16 +125,15 @@ void CALL11(___Thread______sleep____J, long long ___millis___, long long ___mill
 #endif
 }
 
+#ifdef DSTM
 /* Add thread join capability */
 void CALL01(___Thread______join____, struct ___Thread___ * ___this___) {
-  printf("DEBUG -> Inside thread join\n");
-#ifdef DSTM
-  pthread_t thread;
-  unsigned int *oidarray, mid;
+  unsigned int *oidarray;
   unsigned short *versionarray, version;
   transrecord_t *trans;
   objheader_t *ptr;
   /* Add transaction to check if thread finished for join operation */
+  goto transstart;
 transstart:
   trans = transStart();
   ptr = transRead(trans, (unsigned int) VAR(___this___));
@@ -156,17 +156,22 @@ transstart:
                  return;
          }
          versionarray[0] = version;
-         mid = lhashSearch((unsigned int) VAR(___this___));
          /* Request Notification */
-         reqNotify(oidarray, versionarray, mid, 1); 
+#ifdef PRECISE_GC
+         struct listitem *tmp=stopforgc((struct garbagelist *)___params___);
+#endif
+         reqNotify(oidarray, versionarray, 1); 
+#ifdef PRECISE_GC
+         restartaftergc(tmp);
+#endif
          free(oidarray);
          free(versionarray);
          transAbort(trans);
          goto transstart;
   }
   return;
-#endif
 }
+#endif
 
 #ifdef THREADS
 void CALL01(___Thread______nativeCreate____, struct ___Thread___ * ___this___) {
@@ -199,11 +204,12 @@ void CALL12(___Thread______start____I, int ___mid___, struct ___Thread___ * ___t
 #ifdef DSTM
 void globalDestructor(void *value) {
        free(value);
-       pthread_setspecific(oid, NULL);
+       pthread_setspecific(oidval, NULL);
 }
 
 void initDSMthread(int *ptr) {
   objheader_t *tmp;    
+  transrecord_t * trans;
   void *threadData;
   int oid=ptr[0];
   int type=ptr[1];
@@ -216,7 +222,7 @@ void initDSMthread(int *ptr) {
 #endif
   threadData = calloc(1, sizeof(unsigned int));
   *((unsigned int *) threadData) = oid;
-  pthread_setspecific(oid, threadData);
+  pthread_setspecific(oidval, threadData);
   pthread_mutex_lock(&gclistlock);
   threadcount--;
   pthread_cond_signal(&gccond);
@@ -224,32 +230,32 @@ void initDSMthread(int *ptr) {
   /* Add transaction to check if thread finished for join operation */
   goto transstart;
 transstart:
-  trans = transStart();
-  tmp  = transRead(trans, (unsigned int) oid);
-  struct ___Thread___ *t = (struct ___Thread___ *) tmp;
-  t->___threadDone___ = 1;
-  while(!transCommit(trans)) {
-         printf("DEBUG-> Trans not committed yet\n");
-         transAbort(trans);
-         goto transstart;
+  {
+    transrecord_t * trans = transStart();
+    tmp  = transRead(trans, (unsigned int) oid);
+    ((struct ___Thread___ *)tmp)->___threadDone___ = 1;
+    *((unsigned int *)&((struct ___Object___ *) tmp)->___localcopy___) |=DIRTY;
+    if(transCommit(trans)!= 0) {
+      goto transstart;
+    }
   }
   pthread_exit(NULL);
 }
 
 void startDSMthread(int oid, int objType) {
-  pthread_t thread;
-  int retval;
-  pthread_attr_t nattr;
+       pthread_t thread;
+       int retval;
+       pthread_attr_t nattr;
 
-  pthread_mutex_lock(&gclistlock);
-  threadcount++;
-  pthread_mutex_unlock(&gclistlock);
+       pthread_mutex_lock(&gclistlock);
+       threadcount++;
+       pthread_mutex_unlock(&gclistlock);
   pthread_attr_init(&nattr);
   pthread_attr_setdetachstate(&nattr, PTHREAD_CREATE_DETACHED);
   int * ptr=malloc(sizeof(int)*2);
   ptr[0]=oid;
   ptr[1]=objType;
-  pthread_key_create(&oid, globalDestructor);
+  pthread_key_create(&oidval, globalDestructor);
   do {
     retval=pthread_create(&thread, &nattr, (void * (*)(void *)) &initDSMthread,  ptr);
     if (retval!=0)