Fix tabbing.... Please fix your editors so they do tabbing correctly!!! (Spaces...
[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 #ifdef MAC
41   struct lockvector *lptr=(struct lockvector *)pthread_getspecific(threadlocks);
42   int self=(int)(long)pthread_getspecific(macthreadid);
43 #else
44   struct lockvector *lptr=&lvector;
45   int self=mythreadid;
46 #endif
47   struct lockpair *lpair=&lptr->locks[lptr->index++];
48   lpair->object=VAR(___this___);
49
50   if (self==VAR(___this___)->tid) {
51     lpair->islastlock=0;
52   } else {
53     lpair->islastlock=1;
54     while(1) {
55       if (VAR(___this___)->tid==0) {
56         if (CAS32(&VAR(___this___)->tid, 0, self)==0) {
57           return;
58         }
59       }
60       {
61 #ifdef PRECISE_GC
62         if (unlikely(needtocollect))
63           checkcollect((struct garbagelist *)___params___);
64 #endif
65       }
66     }
67   }
68 }
69 #endif
70
71
72 #ifdef D___Object______notify____
73 void CALL01(___Object______notify____, struct ___Object___ * ___this___) {
74   VAR(___this___)->notifycount++;
75 }
76 #endif
77
78 #ifdef D___Object______notifyAll____
79 void CALL01(___Object______notifyAll____, struct ___Object___ * ___this___) {
80   VAR(___this___)->notifycount++;
81 }
82 #endif
83
84 #ifdef D___Object______wait____
85 void CALL01(___Object______wait____, struct ___Object___ * ___this___) {
86 #ifdef MAC
87   int self=(int)(long)pthread_getspecific(macthreadid);
88 #else
89   int self=mythreadid;
90 #endif
91   int notifycount=VAR(___this___)->notifycount;
92   BARRIER();
93   VAR(___this___)->tid=0;
94   BARRIER();
95
96   while(notifycount==VAR(___this___)->notifycount) {
97 #ifdef PRECISE_GC
98     if (unlikely(needtocollect))
99       checkcollect((struct garbagelist *)___params___);
100 #endif
101   }
102
103   while(1) {
104     if (VAR(___this___)->tid==0) {
105       if (CAS32(&VAR(___this___)->tid, 0, self)==0) {
106         BARRIER();
107         return;
108       }
109     }
110 #ifdef PRECISE_GC
111     if (unlikely(needtocollect))
112       checkcollect((struct garbagelist *)___params___);
113 #endif
114   }
115 }
116 #endif
117
118 #ifdef D___Object______MonitorExit____
119 void CALL01(___Object______MonitorExit____, struct ___Object___ * ___this___) {
120 #ifdef MAC
121   struct lockvector *lptr=(struct lockvector *)pthread_getspecific(threadlocks);
122 #else
123   struct lockvector *lptr=&lvector;
124 #endif
125   struct lockpair *lpair=&lptr->locks[--lptr->index];
126
127   if (lpair->islastlock) {
128     MBARRIER();
129     lpair->object->tid=0;
130   }
131 }
132 #endif
133 #endif