- we now build a libnat.a
[cacao.git] / src / native / vm / VMThread.c
1 /* class: java/lang/Thread */
2
3
4 #include "jni.h"
5 #include "types.h"
6 #include "native.h"
7 #include "loader.h"
8 #include "tables.h"
9 #include "threads/thread.h"
10 #include "java_lang_ThreadGroup.h"
11 #include "java_lang_Object.h"         /* needed for java_lang_Thread.h */
12 #include "java_lang_Throwable.h"      /* needed for java_lang_Thread.h */
13 #include "java_lang_Thread.h"
14
15
16 /*
17  * Class:     java/lang/Thread
18  * Method:    countStackFrames
19  * Signature: ()I
20  */
21 JNIEXPORT s4 JNICALL Java_java_lang_Thread_countStackFrames ( JNIEnv *env ,  struct java_lang_Thread* this)
22 {
23     log_text ("java_lang_Thread_countStackFrames called");
24     return 0;         /* not yet implemented */
25 }
26
27 /*
28  * Class:     java/lang/Thread
29  * Method:    currentThread
30  * Signature: ()Ljava/lang/Thread;
31  */
32 JNIEXPORT struct java_lang_Thread* JNICALL Java_java_lang_Thread_currentThread ( JNIEnv *env ,jclass clazz )
33 {
34   struct java_lang_Thread* t;
35
36   if (runverbose)
37     log_text ("java_lang_Thread_currentThread called");
38
39
40   #ifdef USE_THREADS
41
42          t = (struct java_lang_Thread*) currentThread; 
43   
44          if (!t->group) {
45                 log_text("java_lang_Thread_currentThread: t->group=NULL");
46                 /* ThreadGroup of currentThread is not initialized */
47
48                 t->group = (java_lang_ThreadGroup *) 
49                         native_new_and_init(loader_load(utf_new_char("java/lang/ThreadGroup")));
50
51                 if (t->group == 0) 
52                         log_text("unable to create ThreadGroup");
53         }
54
55         return (struct java_lang_Thread*) currentThread;
56   #else
57         return 0;       
58   #endif
59 }
60
61 /*
62  * Class:     java/lang/Thread
63  * Method:    nativeInterrupt
64  * Signature: ()V
65  */
66 JNIEXPORT void JNICALL Java_java_lang_Thread_nativeInterrupt ( JNIEnv *env ,  struct java_lang_Thread* this)
67 {
68   log_text("Java_java_lang_Thread_interrupt0  called");
69   /* not yet implemented */
70 }
71
72 /*
73  * Class:     java/lang/Thread
74  * Method:    isAlive
75  * Signature: ()Z
76  */
77 JNIEXPORT s4 JNICALL Java_java_lang_Thread_isAlive ( JNIEnv *env ,  struct java_lang_Thread* this)
78 {
79     if (runverbose)
80         log_text ("java_lang_Thread_isAlive called");
81
82 #ifdef USE_THREADS
83     return aliveThread((thread*)this);
84 #else
85     return 0;
86 #endif
87 }
88
89
90
91 /*
92  * Class:     java_lang_Thread
93  * Method:    isInterrupted
94  * Signature: ()Z
95  */
96 JNIEXPORT s4 JNICALL Java_java_lang_Thread_isInterrupted (JNIEnv *env ,  struct java_lang_Thread* this )
97 {
98     log_text("Java_java_lang_Thread_isInterrupted  called");
99     return 0;                   /* not yet implemented */
100 }
101
102 /*
103  * Class:     java/lang/Thread
104  * Method:    registerNatives
105  * Signature: ()V
106  */
107 JNIEXPORT void JNICALL Java_java_lang_Thread_registerNatives ( JNIEnv *env ,jclass clazz )
108 {
109   /* empty */
110 }
111
112 /*
113  * Class:     java/lang/Thread
114  * Method:    resume0
115  * Signature: ()V
116  */
117 JNIEXPORT void JNICALL Java_java_lang_Thread_nativeResume ( JNIEnv *env ,  struct java_lang_Thread* this)
118 {
119     if (runverbose)
120         log_text ("java_lang_Thread_resume0 called");
121
122 #ifdef USE_THREADS
123     resumeThread((thread*)this);
124 #endif
125 }
126
127 /*
128  * Class:     java/lang/Thread
129  * Method:    setPriority0
130  * Signature: (I)V
131  */
132 JNIEXPORT void JNICALL Java_java_lang_Thread_nativeSetPriority ( JNIEnv *env ,  struct java_lang_Thread* this, s4 par1)
133 {
134     if (runverbose) 
135         log_text ("java_lang_Thread_setPriority0 called");
136
137 #ifdef USE_THREADS
138     setPriorityThread((thread*)this, par1);
139 #endif
140 }
141
142
143 /*
144  * Class:     java_lang_Thread
145  * Method:    sleep
146  * Signature: (JI)V
147  */
148 JNIEXPORT void JNICALL Java_java_lang_Thread_sleep (JNIEnv *env , jclass clazz, s8 millis, s4 par2)
149 {
150     if (runverbose)
151         log_text ("java_lang_Thread_sleep called");
152
153 #ifdef USE_THREADS
154     sleepThread(millis);
155 #endif
156 }
157
158 /*
159  * Class:     java/lang/Thread
160  * Method:    start
161  * Signature: ()V
162  */
163 JNIEXPORT void JNICALL Java_java_lang_Thread_start ( JNIEnv *env ,  struct java_lang_Thread* this)
164 {
165   if (runverbose) 
166     log_text ("java_lang_Thread_start called");
167     /*printf("THREAD PRIORITY: %d\n",this->priority);*/
168
169   #ifdef USE_THREADS
170         startThread((thread*)this);
171   #endif
172 }
173
174 /*
175  * Class:     java/lang/Thread
176  * Method:    stop0
177  * Signature: (Ljava/lang/Object;)V
178  */
179 JNIEXPORT void JNICALL Java_java_lang_Thread_nativeStop ( JNIEnv *env ,  struct java_lang_Thread* this, struct java_lang_Throwable* par1)
180 {
181   if (runverbose)
182     log_text ("java_lang_Thread_stop0 called");
183
184
185   #ifdef USE_THREADS
186         if (currentThread == (thread*)this)
187         {
188             log_text("killing");
189             killThread(0);
190             /*
191                 exceptionptr = proto_java_lang_ThreadDeath;
192                 return;
193             */
194         }
195         else
196         {
197                 CONTEXT((thread*)this).flags |= THREAD_FLAGS_KILLED;
198                 resumeThread((thread*)this);
199         }
200    #endif
201 }
202
203 /*
204  * Class:     java/lang/Thread
205  * Method:    suspend0
206  * Signature: ()V
207  */
208 JNIEXPORT void JNICALL Java_java_lang_Thread_nativeSuspend ( JNIEnv *env ,  struct java_lang_Thread* this)
209 {
210   if (runverbose)
211     log_text ("java_lang_Thread_suspend0 called");
212
213   #ifdef USE_THREADS
214         suspendThread((thread*)this);
215   #endif
216
217 }
218
219 /*
220  * Class:     java/lang/Thread
221  * Method:    yield
222  * Signature: ()V
223  */
224 JNIEXPORT void JNICALL Java_java_lang_Thread_yield ( JNIEnv *env  ,jclass clazz)
225 {
226   if (runverbose)
227     log_text ("java_lang_Thread_yield called");
228   #ifdef USE_THREADS
229         yieldThread();
230   #endif
231 }
232
233 /*
234  * Class:     java_lang_Thread
235  * Method:    interrupted
236  * Signature: ()Z
237  */
238 JNIEXPORT s4 JNICALL Java_java_lang_Thread_interrupted (JNIEnv *env ,jclass clazz) {
239         log_text("Java_java_lang_Thread_interrupted");
240         return 0;
241 }
242 /*
243  * Class:     java_lang_Thread
244  * Method:    nativeInit
245  * Signature: (J)V
246  */
247 JNIEXPORT void JNICALL Java_java_lang_Thread_nativeInit (JNIEnv *env ,  struct java_lang_Thread* this , s8 par1) {
248         log_text("Thread_nativeInit");
249         if (exceptionptr) log_text("There has been an exception, strange...");
250         this->priority=5;
251 }
252
253 /*
254  * Class:     java_lang_Thread
255  * Method:    holdsLock
256  * Signature: (Ljava/lang/Object;)Z
257  */
258 JNIEXPORT s4 JNICALL Java_java_lang_Thread_holdsLock (JNIEnv *env , jclass clazz, struct java_lang_Object* par1)
259 {
260   return 0;
261 }
262
263
264 /*
265  * These are local overrides for various environment variables in Emacs.
266  * Please do not remove this and leave it at the end of the file, where
267  * Emacs will automagically detect them.
268  * ---------------------------------------------------------------------
269  * Local variables:
270  * mode: c
271  * indent-tabs-mode: t
272  * c-basic-offset: 4
273  * tab-width: 4
274  * End:
275  */