more change for PMC
[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 #ifdef THREADS
18 __thread struct lockvector lvector;
19 __thread int mythreadid;
20 #endif
21 #else
22
23 #endif
24
25 #ifdef D___Object______hashCode____
26 int CALL01(___Object______hashCode____, struct ___Object___ * ___this___) {
27   return VAR(___this___)->hashcode;
28 }
29 #endif
30
31 #ifdef D___Object______getType____
32 int CALL01(___Object______getType____, struct ___Object___ * ___this___) {
33   return ((int *)VAR(___this___))[0];
34 }
35 #endif
36
37 #ifdef THREADS
38 #ifdef D___Object______MonitorEnter____
39 void CALL01(___Object______MonitorEnter____, struct ___Object___ * ___this___) {
40 #ifndef NOLOCK
41 #ifdef MAC
42   struct lockvector *lptr=(struct lockvector *)pthread_getspecific(threadlocks);
43   int self=(int)(long)pthread_getspecific(macthreadid);
44 #else
45   struct lockvector *lptr=&lvector;
46   int self=mythreadid;
47 #endif
48   struct lockpair *lpair=&lptr->locks[lptr->index++];
49   lpair->object=VAR(___this___);
50
51   if (self==VAR(___this___)->tid) {
52     lpair->islastlock=0;
53   } else {
54     lpair->islastlock=1;
55     while(1) {
56       if (VAR(___this___)->tid==0) {
57         if (CAS32(&VAR(___this___)->tid, 0, self)==0) {
58           return;
59         }
60       }
61       {
62 #ifdef PRECISE_GC
63         if (unlikely(needtocollect))
64           checkcollect((struct garbagelist *)___params___);
65 #endif
66       }
67     }
68   }
69 #endif
70 }
71 #endif
72
73
74 #ifdef D___Object______notify____
75 void CALL01(___Object______notify____, struct ___Object___ * ___this___) {
76   VAR(___this___)->notifycount++;
77 }
78 #endif
79
80 #ifdef D___Object______notifyAll____
81 void CALL01(___Object______notifyAll____, struct ___Object___ * ___this___) {
82   VAR(___this___)->notifycount++;
83 }
84 #endif
85
86 #ifdef D___Object______wait____
87 void CALL01(___Object______wait____, struct ___Object___ * ___this___) {
88 #ifdef MAC
89   int self=(int)(long)pthread_getspecific(macthreadid);
90 #else
91   int self=mythreadid;
92 #endif
93   int notifycount=VAR(___this___)->notifycount;
94   BARRIER();
95   VAR(___this___)->tid=0;
96   BARRIER();
97
98   while(notifycount==VAR(___this___)->notifycount) {
99 #ifdef PRECISE_GC
100     if (unlikely(needtocollect))
101       checkcollect((struct garbagelist *)___params___);
102 #endif
103   }
104
105   while(1) {
106     if (VAR(___this___)->tid==0) {
107       if (CAS32(&VAR(___this___)->tid, 0, self)==0) {
108         BARRIER();
109         return;
110       }
111     }
112 #ifdef PRECISE_GC
113     if (unlikely(needtocollect))
114       checkcollect((struct garbagelist *)___params___);
115 #endif
116   }
117 }
118 #endif
119
120 #ifdef D___Object______MonitorExit____
121 void CALL01(___Object______MonitorExit____, struct ___Object___ * ___this___) {
122 #ifndef NOLOCK
123 #ifdef MAC
124   struct lockvector *lptr=(struct lockvector *)pthread_getspecific(threadlocks);
125 #else
126   struct lockvector *lptr=&lvector;
127 #endif
128   struct lockpair *lpair=&lptr->locks[--lptr->index];
129
130   if (lpair->islastlock) {
131     MBARRIER();
132     lpair->object->tid=0;
133   }
134 #endif
135 }
136 #endif
137 #endif