add object files
authorbdemsky <bdemsky>
Tue, 20 Feb 2007 08:50:50 +0000 (08:50 +0000)
committerbdemsky <bdemsky>
Tue, 20 Feb 2007 08:50:50 +0000 (08:50 +0000)
Robust/src/Runtime/object.c [new file with mode: 0644]
Robust/src/Runtime/object.h [new file with mode: 0644]

diff --git a/Robust/src/Runtime/object.c b/Robust/src/Runtime/object.c
new file mode 100644 (file)
index 0000000..352637d
--- /dev/null
@@ -0,0 +1,64 @@
+#include "object.h"
+#include "stdio.h"
+#include "stdlib.h"
+
+#ifdef THREADS
+#include "thread.h"
+#endif
+
+int CALL01(___Object______hashCode____, struct ___Object___ * ___this___) {
+  return (int) VAR(___this___);
+}
+
+int CALL01(___Object______getType____, struct ___Object___ * ___this___) {
+  return ((int *)VAR(___this___))[0];
+}
+
+#ifdef THREADS
+int CALL01(___Object______MonitorEnter____, struct ___Object___ * ___this___) {
+  pthread_t self=pthread_self();
+  if (self==VAR(___this___)->tid) {
+    VAR(___this___)->lockcount++;
+  } else {
+#ifdef PRECISEGC
+    struct listitem *tmp=stopforgc(stackptr);
+#endif
+    pthread_mutex_lock(&objlock);
+#ifdef PRECISEGC
+    restartaftergc(tmp);
+#endif
+    while(1) {
+      if (VAR(___this___)->tid==0) {
+       VAR(___this___)->lockcount=1;
+       VAR(___this___)->tid=self;
+       pthread_mutex_unlock(&objlock);
+       break;
+      }
+      {
+#ifdef PRECISEGC
+       struct listitem *tmp=stopforgc(stackptr);
+#endif
+       pthread_cond_wait(&objcond, &objlock);
+#ifdef PRECISEGC
+       restartaftergc(tmp);
+#endif
+      }
+    }
+  }
+}
+
+int CALL01(___Object______MonitorExit____, struct ___Object___ * ___this___) {
+  pthread_t self=pthread_self();
+  if (self==VAR(___this___)->tid) {
+    VAR(___this___)->lockcount--;
+    if (VAR(___this___)->lockcount==0)
+      VAR(___this___)->tid=0;
+    pthread_mutex_lock(&objlock);
+    pthread_cond_broadcast(&objcond);
+    pthread_mutex_unlock(&objlock);
+  } else {
+    printf("ERROR...UNLOCKING LOCK WE DON'T HAVE\n");
+    exit(-1);
+  }
+}
+#endif
diff --git a/Robust/src/Runtime/object.h b/Robust/src/Runtime/object.h
new file mode 100644 (file)
index 0000000..73e201d
--- /dev/null
@@ -0,0 +1,12 @@
+#ifndef OBJECT_H
+#define OBJECT_H
+#include "runtime.h"
+#include "structdefs.h"
+
+int CALL01(___Object______hashCode____, struct ___Object___ * ___this___);
+int CALL01(___Object______getType____, struct ___Object___ * ___this___);
+#ifdef THREADS
+int CALL01(___Object______MonitorEnter____, struct ___Object___ * ___this___);
+int CALL01(___Object______MonitorExit____, struct ___Object___ * ___this___);
+#endif
+#endif