+#if defined(DSTM)|| defined(THREADS)||defined(STM)
+void CALL00(___Thread______yield____) {
+ pthread_yield();
+}
+#endif
+
+#ifdef D___Thread______abort____
+void CALL00(___Thread______abort____) {
+#ifdef SANDBOX
+ _longjmp(aborttrans,1);
+#endif
+}
+#endif
+
+#ifdef DSTM
+#ifdef RECOVERY
+// return if the machine is dead
+int CALL12(___Thread______nativeGetStatus____I, int ___mid___, struct ___Thread___ * ___this___, int ___mid___) {
+ return getStatus(___mid___);
+}
+#else
+int CALL12(___Thread______nativeGetStatus____I, int ___mid___, struct ___Thread___ * ___this___, int ___mid___) {
+ return 0;
+}
+#endif
+#endif
+#ifdef DSTM
+/* Add thread join capability */
+void CALL01(___Thread______join____, struct ___Thread___ * ___this___) {
+ unsigned int *oidarray;
+ unsigned short *versionarray, version;
+ objheader_t *ptr;
+ /* Add transaction to check if thread finished for join operation */
+transstart:
+ transStart();
+ ptr = transRead((unsigned int) VAR(___this___));
+ struct ___Thread___ *p = (struct ___Thread___ *) ptr;
+#ifdef THREADJOINDEBUG
+ printf("Start join process for Oid = %x\n", (unsigned int) VAR(___this___));
+#endif
+ if(p->___threadDone___ == 1) {
+#ifdef THREADJOINDEBUG
+ printf("Thread oid = %x is done\n", (unsigned int) VAR(___this___));
+#endif
+ transAbort();
+ return;
+ }
+#ifdef RECOVERY
+ else if( checkiftheMachineDead(p->___mid___) == 0) {
+ printf("Thread oid = %x is dead\n", (unsigned int) VAR(___this___));
+ transAbort();
+ return;
+ }
+#endif
+ else {
+ version = (ptr-1)->version;
+ if((oidarray = calloc(1, sizeof(unsigned int))) == NULL) {
+ printf("Calloc error %s, %d\n", __FILE__, __LINE__);
+ return;
+ }
+
+ oidarray[0] = (unsigned int) VAR(___this___);
+
+ if((versionarray = calloc(1, sizeof(unsigned short))) == NULL) {
+ printf("Calloc error %s, %d\n", __FILE__, __LINE__);
+ free(oidarray);
+ return;
+ }
+ versionarray[0] = version;
+ /* Request Notification */
+#ifdef PRECISE_GC
+ stopforgc((struct garbagelist *)___params___);
+#endif
+
+#ifdef RECOVERY
+ reqNotify(oidarray, versionarray, 1,p->___mid___);
+#else
+ reqNotify(oidarray, versionarray, 1);
+#endif
+#ifdef PRECISE_GC
+ restartaftergc();
+#endif
+ free(oidarray);
+ free(versionarray);
+ transAbort();
+ goto transstart;
+ }
+ return;
+}
+#endif
+
+#if defined(THREADS)||defined(STM)
+void CALL01(___Thread______nativeJoin____, struct ___Thread___ * ___this___) {
+ pthread_mutex_lock(&joinlock);
+ while(!VAR(___this___)->___finished___) {
+#ifdef PRECISE_GC
+ stopforgc((struct garbagelist *)___params___);
+#endif
+ pthread_cond_wait(&joincond, &joinlock);
+#ifdef PRECISE_GC
+ restartaftergc();
+#endif
+ }
+ pthread_mutex_unlock(&joinlock);
+}
+