737034c9b51db8770b47f2db4297bb7b8589869b
[cacao.git] / src / native / vm / VMThread.c
1 /* class: java/lang/Thread */
2
3 /*
4  * Class:     java/lang/Thread
5  * Method:    countStackFrames
6  * Signature: ()I
7  */
8 JNIEXPORT s4 JNICALL Java_java_lang_Thread_countStackFrames ( JNIEnv *env ,  struct java_lang_Thread* this)
9 {
10   log_text ("java_lang_Thread_countStackFrames called");
11   return 0;         /* not yet implemented */
12 }
13
14 /*
15  * Class:     java/lang/Thread
16  * Method:    currentThread
17  * Signature: ()Ljava/lang/Thread;
18  */
19 JNIEXPORT struct java_lang_Thread* JNICALL Java_java_lang_Thread_currentThread ( JNIEnv *env  )
20 {
21   struct java_lang_Thread* t;
22
23   if (runverbose)
24     log_text ("java_lang_Thread_currentThread called");
25
26
27   #ifdef USE_THREADS
28
29          t = (struct java_lang_Thread*) currentThread; 
30   
31          if (!t->group) {
32
33                 /* ThreadGroup of currentThread is not initialized */
34
35                 t->group = (java_lang_ThreadGroup *) 
36                         native_new_and_init(loader_load(utf_new_char("java/lang/ThreadGroup")));
37
38                 if (t->group == 0) 
39                         log_text("unable to create ThreadGroup");
40         }
41
42
43         return (struct java_lang_Thread*) currentThread;
44   #else
45         return 0;       
46   #endif
47 }
48
49 /*
50  * Class:     java/lang/Thread
51  * Method:    interrupt0
52  * Signature: ()V
53  */
54 JNIEXPORT void JNICALL Java_java_lang_Thread_interrupt0 ( JNIEnv *env ,  struct java_lang_Thread* this)
55 {
56   log_text("Java_java_lang_Thread_interrupt0  called");
57 }
58
59 /*
60  * Class:     java/lang/Thread
61  * Method:    isAlive
62  * Signature: ()Z
63  */
64 JNIEXPORT s4 JNICALL Java_java_lang_Thread_isAlive ( JNIEnv *env ,  struct java_lang_Thread* this)
65 {
66   if (runverbose)
67     log_text ("java_lang_Thread_isAlive called");
68
69   #ifdef USE_THREADS
70         return aliveThread((thread*)this);
71   #else
72         return 0;
73   #endif
74 }
75
76 /*
77  * Class:     java/lang/Thread
78  * Method:    isInterrupted
79  * Signature: (Z)Z
80  */
81 JNIEXPORT s4 JNICALL Java_java_lang_Thread_isInterrupted ( JNIEnv *env ,  struct java_lang_Thread* this, s4 par1)
82 {
83   log_text("Java_java_lang_Thread_isInterrupted  called");
84 }
85
86 /*
87  * Class:     java/lang/Thread
88  * Method:    registerNatives
89  * Signature: ()V
90  */
91 JNIEXPORT void JNICALL Java_java_lang_Thread_registerNatives ( JNIEnv *env  )
92 {
93   /* empty */
94 }
95
96 /*
97  * Class:     java/lang/Thread
98  * Method:    resume0
99  * Signature: ()V
100  */
101 JNIEXPORT void JNICALL Java_java_lang_Thread_resume0 ( JNIEnv *env ,  struct java_lang_Thread* this)
102 {
103   if (runverbose)
104     log_text ("java_lang_Thread_resume0 called");
105
106   #ifdef USE_THREADS
107         resumeThread((thread*)this);
108   #endif
109 }
110
111 /*
112  * Class:     java/lang/Thread
113  * Method:    setPriority0
114  * Signature: (I)V
115  */
116 JNIEXPORT void JNICALL Java_java_lang_Thread_setPriority0 ( JNIEnv *env ,  struct java_lang_Thread* this, s4 par1)
117 {
118   if (runverbose) 
119     log_text ("java_lang_Thread_setPriority0 called");
120
121   #ifdef USE_THREADS
122   setPriorityThread((thread*)this, par1);
123   #endif
124 }
125
126 /*
127  * Class:     java/lang/Thread
128  * Method:    sleep
129  * Signature: (J)V
130  */
131 JNIEXPORT void JNICALL Java_java_lang_Thread_sleep ( JNIEnv *env ,  s8 par1)
132 {
133   if (runverbose)
134     log_text ("java_lang_Thread_sleep called");
135
136   #ifdef USE_THREADS
137         yieldThread();
138   #endif
139         
140   /* not yet implemented */
141 }
142
143 /*
144  * Class:     java/lang/Thread
145  * Method:    start
146  * Signature: ()V
147  */
148 JNIEXPORT void JNICALL Java_java_lang_Thread_start ( JNIEnv *env ,  struct java_lang_Thread* this)
149 {
150   if (runverbose) 
151     log_text ("java_lang_Thread_start called");
152
153   #ifdef USE_THREADS
154         startThread((thread*)this);
155   #endif
156 }
157
158 /*
159  * Class:     java/lang/Thread
160  * Method:    stop0
161  * Signature: (Ljava/lang/Object;)V
162  */
163 JNIEXPORT void JNICALL Java_java_lang_Thread_stop0 ( JNIEnv *env ,  struct java_lang_Thread* this, struct java_lang_Object* par1)
164 {
165   if (runverbose)
166     log_text ("java_lang_Thread_stop0 called");
167
168
169   #ifdef USE_THREADS
170         if (currentThread == (thread*)this)
171         {
172             log_text("killing");
173             killThread(0);
174             /*
175                 exceptionptr = proto_java_lang_ThreadDeath;
176                 return;
177             */
178         }
179         else
180         {
181                 CONTEXT((thread*)this).flags |= THREAD_FLAGS_KILLED;
182                 resumeThread((thread*)this);
183         }
184    #endif
185 }
186
187 /*
188  * Class:     java/lang/Thread
189  * Method:    suspend0
190  * Signature: ()V
191  */
192 JNIEXPORT void JNICALL Java_java_lang_Thread_suspend0 ( JNIEnv *env ,  struct java_lang_Thread* this)
193 {
194   if (runverbose)
195     log_text ("java_lang_Thread_suspend0 called");
196
197   #ifdef USE_THREADS
198         suspendThread((thread*)this);
199   #endif
200
201 }
202
203 /*
204  * Class:     java/lang/Thread
205  * Method:    yield
206  * Signature: ()V
207  */
208 JNIEXPORT void JNICALL Java_java_lang_Thread_yield ( JNIEnv *env  )
209 {
210   if (runverbose)
211     log_text ("java_lang_Thread_yield called");
212   #ifdef USE_THREADS
213         yieldThread();
214   #endif
215 }
216
217
218
219
220
221
222
223