add batch-mode script
[IRC.git] / Robust / src / Runtime / object.c
index 091b1218aedcc72071bd6d792041351a64f762f0..d9b775b49fa56d053efd726ebed4d193e6f279bf 100644 (file)
 #endif
 
 #ifndef MAC
+#ifdef THREADS
 __thread struct lockvector lvector;
+__thread int mythreadid;
 #endif
+#else
 
-#ifdef D___Object______nativehashCode____
-int CALL01(___Object______nativehashCode____, struct ___Object___ * ___this___) {
-  return (int)((INTPTR) VAR(___this___));
-}
 #endif
 
 #ifdef D___Object______hashCode____
 int CALL01(___Object______hashCode____, struct ___Object___ * ___this___) {
-  if (!VAR(___this___)->___cachedHash___) {
-    VAR(___this___)->___cachedHash___=1;
-    VAR(___this___)->___cachedCode___=(int)((INTPTR)VAR(___this___));
-  }
-  return VAR(___this___)->___cachedCode___;
+  return VAR(___this___)->hashcode;
 }
 #endif
 
@@ -42,13 +37,15 @@ int CALL01(___Object______getType____, struct ___Object___ * ___this___) {
 #ifdef THREADS
 #ifdef D___Object______MonitorEnter____
 void CALL01(___Object______MonitorEnter____, struct ___Object___ * ___this___) {
+#ifndef NOLOCK
 #ifdef MAC
   struct lockvector *lptr=(struct lockvector *)pthread_getspecific(threadlocks);
+  int self=(int)(long)pthread_getspecific(macthreadid);
 #else
   struct lockvector *lptr=&lvector;
+  int self=mythreadid;
 #endif
   struct lockpair *lpair=&lptr->locks[lptr->index++];
-  pthread_t self=pthread_self();
   lpair->object=VAR(___this___);
 
   if (self==VAR(___this___)->tid) {
@@ -56,20 +53,20 @@ void CALL01(___Object______MonitorEnter____, struct ___Object___ * ___this___) {
   } else {
     lpair->islastlock=1;
     while(1) {
-      if (VAR(___this___)->lockcount==0) {
-       if (LOCKXCHG32(&VAR(___this___)->lockcount, 1)==0) {
-         VAR(___this___)->tid=self;
-         return;
-       }
+      if (VAR(___this___)->tid==0) {
+        if (CAS32(&VAR(___this___)->tid, 0, self)==0) {
+          return;
+        }
       }
       {
 #ifdef PRECISE_GC
-       if (unlikely(needtocollect))
-         checkcollect((struct garbagelist *)___params___);
+        if (unlikely(needtocollect))
+          checkcollect((struct garbagelist *)___params___);
 #endif
       }
     }
   }
+#endif
 }
 #endif
 
@@ -88,13 +85,16 @@ void CALL01(___Object______notifyAll____, struct ___Object___ * ___this___) {
 
 #ifdef D___Object______wait____
 void CALL01(___Object______wait____, struct ___Object___ * ___this___) {
-  pthread_t self=pthread_self();
+#ifdef MAC
+  int self=(int)(long)pthread_getspecific(macthreadid);
+#else
+  int self=mythreadid;
+#endif
   int notifycount=VAR(___this___)->notifycount;
   BARRIER();
   VAR(___this___)->tid=0;
   BARRIER();
-  VAR(___this___)->lockcount=0;
-  
+
   while(notifycount==VAR(___this___)->notifycount) {
 #ifdef PRECISE_GC
     if (unlikely(needtocollect))
@@ -103,11 +103,10 @@ void CALL01(___Object______wait____, struct ___Object___ * ___this___) {
   }
 
   while(1) {
-    if (VAR(___this___)->lockcount==0) {
-      if (LOCKXCHG32(&VAR(___this___)->lockcount, 1)==0) {
-       VAR(___this___)->tid=self;
-       BARRIER();
-       return;
+    if (VAR(___this___)->tid==0) {
+      if (CAS32(&VAR(___this___)->tid, 0, self)==0) {
+        BARRIER();
+        return;
       }
     }
 #ifdef PRECISE_GC
@@ -120,18 +119,19 @@ void CALL01(___Object______wait____, struct ___Object___ * ___this___) {
 
 #ifdef D___Object______MonitorExit____
 void CALL01(___Object______MonitorExit____, struct ___Object___ * ___this___) {
+#ifndef NOLOCK
 #ifdef MAC
   struct lockvector *lptr=(struct lockvector *)pthread_getspecific(threadlocks);
 #else
   struct lockvector *lptr=&lvector;
 #endif
   struct lockpair *lpair=&lptr->locks[--lptr->index];
-  
+
   if (lpair->islastlock) {
-    lpair->object->tid=0;
     MBARRIER();
-    lpair->object->lockcount=0;
+    lpair->object->tid=0;
   }
+#endif
 }
 #endif
 #endif