move hashcode into header...part of prep to switch class libraries
[IRC.git] / Robust / src / Runtime / object.c
1 #include "object.h"
2 #ifdef MULTICORE
3 #include "runtime_arch.h"
4 #else
5 #include "stdio.h"
6 #endif
7 #include "stdlib.h"
8
9 #ifdef THREADS
10 #include "thread.h"
11 #endif
12 #ifndef MULTICORE
13 #include "mlp_lock.h"
14 #endif
15
16 #ifndef MAC
17 __thread struct lockvector lvector;
18 __thread int mythreadid;
19 #else
20
21 #endif
22
23 #ifdef D___Object______hashCode____
24 int CALL01(___Object______hashCode____, struct ___Object___ * ___this___) {
25   return VAR(___this___)->hashcode;
26 }
27 #endif
28
29 #ifdef D___Object______getType____
30 int CALL01(___Object______getType____, struct ___Object___ * ___this___) {
31   return ((int *)VAR(___this___))[0];
32 }
33 #endif
34
35 #ifdef THREADS
36 #ifdef D___Object______MonitorEnter____
37 void CALL01(___Object______MonitorEnter____, struct ___Object___ * ___this___) {
38 #ifdef MAC
39   struct lockvector *lptr=(struct lockvector *)pthread_getspecific(threadlocks);
40   int self=(int)(long)pthread_getspecific(macthreadid);
41 #else
42   struct lockvector *lptr=&lvector;
43   int self=mythreadid;
44 #endif
45   struct lockpair *lpair=&lptr->locks[lptr->index++];
46   lpair->object=VAR(___this___);
47
48   if (self==VAR(___this___)->tid) {
49     lpair->islastlock=0;
50   } else {
51     lpair->islastlock=1;
52     while(1) {
53       if (VAR(___this___)->tid==0) {
54         if (CAS32(&VAR(___this___)->tid, 0, self)==0) {
55           return;
56         }
57       }
58       {
59 #ifdef PRECISE_GC
60         if (unlikely(needtocollect))
61           checkcollect((struct garbagelist *)___params___);
62 #endif
63       }
64     }
65   }
66 }
67 #endif
68
69
70 #ifdef D___Object______notify____
71 void CALL01(___Object______notify____, struct ___Object___ * ___this___) {
72   VAR(___this___)->notifycount++;
73 }
74 #endif
75
76 #ifdef D___Object______notifyAll____
77 void CALL01(___Object______notifyAll____, struct ___Object___ * ___this___) {
78   VAR(___this___)->notifycount++;
79 }
80 #endif
81
82 #ifdef D___Object______wait____
83 void CALL01(___Object______wait____, struct ___Object___ * ___this___) {
84 #ifdef MAC
85   int self=(int)(long)pthread_getspecific(macthreadid);
86 #else
87   int self=mythreadid;
88 #endif
89   int notifycount=VAR(___this___)->notifycount;
90   BARRIER();
91   VAR(___this___)->tid=0;
92   BARRIER();
93   
94   while(notifycount==VAR(___this___)->notifycount) {
95 #ifdef PRECISE_GC
96     if (unlikely(needtocollect))
97       checkcollect((struct garbagelist *)___params___);
98 #endif
99   }
100
101   while(1) {
102     if (VAR(___this___)->tid==0) {
103       if (CAS32(&VAR(___this___)->tid, 0, self)==0) {
104         BARRIER();
105         return;
106       }
107     }
108 #ifdef PRECISE_GC
109     if (unlikely(needtocollect))
110       checkcollect((struct garbagelist *)___params___);
111 #endif
112   }
113 }
114 #endif
115
116 #ifdef D___Object______MonitorExit____
117 void CALL01(___Object______MonitorExit____, struct ___Object___ * ___this___) {
118 #ifdef MAC
119   struct lockvector *lptr=(struct lockvector *)pthread_getspecific(threadlocks);
120 #else
121   struct lockvector *lptr=&lvector;
122 #endif
123   struct lockpair *lpair=&lptr->locks[--lptr->index];
124   
125   if (lpair->islastlock) {
126     MBARRIER();
127     lpair->object->tid=0;
128   }
129 }
130 #endif
131 #endif