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