This commit was manufactured by cvs2svn to create tag 'buildscript'.
[IRC.git] /
1 #include "object.h"
2 #include "stdio.h"
3 #include "stdlib.h"
4
5 #ifdef THREADS
6 #include "thread.h"
7 #endif
8
9 int CALL01(___Object______nativehashCode____, struct ___Object___ * ___this___) {
10   return (int) VAR(___this___);
11 }
12
13 int CALL01(___Object______getType____, struct ___Object___ * ___this___) {
14   return ((int *)VAR(___this___))[0];
15 }
16
17 #ifdef THREADS
18 int CALL01(___Object______MonitorEnter____, struct ___Object___ * ___this___) {
19   pthread_t self=pthread_self();
20   if (self==VAR(___this___)->tid) {
21     VAR(___this___)->lockcount++;
22   } else {
23 #ifdef PRECISE_GC
24     struct listitem *tmp=stopforgc((struct garbagelist *)___params___);
25 #endif
26     pthread_mutex_lock(&objlock);
27 #ifdef PRECISE_GC
28     restartaftergc(tmp);
29 #endif
30     while(1) {
31       if (VAR(___this___)->tid==0) {
32         VAR(___this___)->___prevlockobject___=NULL;
33         VAR(___this___)->___nextlockobject___=(struct ___Object___ *)pthread_getspecific(threadlocks);
34         if (VAR(___this___)->___nextlockobject___!=NULL)
35           VAR(___this___)->___nextlockobject___->___prevlockobject___=VAR(___this___);
36         pthread_setspecific(threadlocks, VAR(___this___));
37         VAR(___this___)->lockcount=1;
38         VAR(___this___)->tid=self;
39         pthread_mutex_unlock(&objlock);
40         break;
41       }
42       {
43 #ifdef PRECISE_GC
44         struct listitem *tmp=stopforgc((struct garbagelist *)___params___);
45 #endif
46         pthread_cond_wait(&objcond, &objlock);
47 #ifdef PRECISE_GC
48         restartaftergc(tmp);
49 #endif
50       }
51     }
52   }
53 }
54
55 int CALL01(___Object______MonitorExit____, struct ___Object___ * ___this___) {
56   pthread_t self=pthread_self();
57   if (self==VAR(___this___)->tid) {
58     VAR(___this___)->lockcount--;
59     if (VAR(___this___)->lockcount==0) {
60       if (VAR(___this___)->___prevlockobject___==NULL) {
61         pthread_setspecific(threadlocks, VAR(___this___)->___nextlockobject___);
62       } else
63         VAR(___this___)->___prevlockobject___->___nextlockobject___=VAR(___this___)->___nextlockobject___;
64       if (VAR(___this___)->___nextlockobject___!=NULL)
65         VAR(___this___)->___nextlockobject___->___prevlockobject___=VAR(___this___)->___prevlockobject___;
66       VAR(___this___)->lockentry=NULL;
67       VAR(___this___)->tid=0;
68     }
69     pthread_mutex_lock(&objlock);
70     pthread_cond_broadcast(&objcond);
71     pthread_mutex_unlock(&objlock);
72   } else {
73     printf("ERROR...UNLOCKING LOCK WE DON'T HAVE\n");
74     exit(-1);
75   }
76 }
77 #endif