change
authorbdemsky <bdemsky>
Sun, 3 Apr 2011 05:26:46 +0000 (05:26 +0000)
committerbdemsky <bdemsky>
Sun, 3 Apr 2011 05:26:46 +0000 (05:26 +0000)
Robust/src/Runtime/object.c

index 4c3c7a03865c7516303c9d603bb5610eb28cbe7e..14d12050d317e3a41380e56776f6766198c87d86 100644 (file)
@@ -69,6 +69,64 @@ int CALL01(___Object______MonitorEnter____, struct ___Object___ * ___this___) {
   }
 #endif
 }
+void CALL01(___Object______notify____, struct ___Object___ * ___this___) {
+  pthread_mutex_lock(&objlock);
+  pthread_cond_broadcast(&objcond);
+  pthread_mutex_unlock(&objlock);
+}
+
+void CALL01(___Object______notifyAll____, struct ___Object___ * ___this___) {
+  pthread_mutex_lock(&objlock);
+  pthread_cond_broadcast(&objcond);
+  pthread_mutex_unlock(&objlock);
+}
+
+void CALL01(___Object______wait____, struct ___Object___ * ___this___) {
+  //release lock
+  int lockcount=VAR(___this___)->lockcount;
+  if (VAR(___this___)->___prevlockobject___==NULL) {
+    pthread_setspecific(threadlocks, VAR(___this___)->___nextlockobject___);
+  } else
+    VAR(___this___)->___prevlockobject___->___nextlockobject___=VAR(___this___)->___nextlockobject___;
+  if (VAR(___this___)->___nextlockobject___!=NULL)
+    VAR(___this___)->___nextlockobject___->___prevlockobject___=VAR(___this___)->___prevlockobject___;
+  VAR(___this___)->lockentry=NULL;
+  VAR(___this___)->tid=0;  
+  //lock released
+  //wait
+#ifdef PRECISE_GC
+  stopforgc((struct garbagelist *)___params___);
+#endif
+  pthread_cond_wait(&objcond, &objlock);
+
+  //grab lock
+  pthread_mutex_lock(&objlock);
+#ifdef PRECISE_GC
+  restartaftergc();
+#endif
+  while(1) {
+    if (VAR(___this___)->tid==0) {
+      VAR(___this___)->___prevlockobject___=NULL;
+      VAR(___this___)->___nextlockobject___=(struct ___Object___ *)pthread_getspecific(threadlocks);
+      if (VAR(___this___)->___nextlockobject___!=NULL)
+       VAR(___this___)->___nextlockobject___->___prevlockobject___=VAR(___this___);
+      pthread_setspecific(threadlocks, VAR(___this___));
+      VAR(___this___)->lockcount=lockcount;
+      VAR(___this___)->tid=self;
+      pthread_mutex_unlock(&objlock);
+      break;
+    }
+    {
+#ifdef PRECISE_GC
+      stopforgc((struct garbagelist *)___params___);
+#endif
+      pthread_cond_wait(&objcond, &objlock);
+#ifdef PRECISE_GC
+      restartaftergc();
+#endif
+    }
+  }
+}
 
 int CALL01(___Object______MonitorExit____, struct ___Object___ * ___this___) {
 #ifndef NOLOCK