* src/vm/jit/i386/darwin/md-asm.h: Repaired --enable-cycles-stats.
[cacao.git] / src / native / vm / cldc1.1 / java_lang_Thread.c
1 /* src/native/vm/cldc1.1/java_lang_Thread.c
2
3    Copyright (C) 2006, 2007 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4    R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5    C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6    Institut f. Computersprachen - TU Wien
7
8    This file is part of CACAO.
9
10    This program is free software; you can redistribute it and/or
11    modify it under the terms of the GNU General Public License as
12    published by the Free Software Foundation; either version 2, or (at
13    your option) any later version.
14
15    This program is distributed in the hope that it will be useful, but
16    WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23    02110-1301, USA.
24
25 */
26
27
28 #include "config.h"
29
30 #include <stdint.h>
31
32 #include "vm/types.h"
33
34 #include "native/jni.h"
35 #include "native/native.h"
36
37 #include "native/include/java_lang_Thread.h"
38
39 #include "native/vm/java_lang_Thread.h"
40
41 #include "threads/threads-common.h"
42
43 #include "toolbox/logging.h"
44
45 #include "vm/builtin.h"
46
47
48 /* native methods implemented by this file ************************************/
49  
50 static JNINativeMethod methods[] = {
51         { "currentThread", "()Ljava/lang/Thread;", (void *) (ptrint) &Java_java_lang_Thread_currentThread },
52         { "setPriority0",  "(II)V",                (void *) (ptrint) &Java_java_lang_Thread_setPriority0  },
53         { "sleep",         "(J)V",                 (void *) (ptrint) &Java_java_lang_Thread_sleep         },
54         { "start0",        "()V",                  (void *) (ptrint) &Java_java_lang_Thread_start0        },
55         { "isAlive",       "()Z",                  (void *) (ptrint) &Java_java_lang_Thread_isAlive       },
56 #if 0
57         { "activeCount",   "()I",                  (void *) (ptrint) &Java_java_lang_Thread_activeCount   },
58         { "setPriority0",  "(II)V",                (void *) (ptrint) &Java_java_lang_Thread_setPriority0  },
59         { "interrupt0",    "()V",                  (void *) (ptrint) &Java_java_lang_Thread_interrupt0    },
60         { "internalExit",  "()V",                  (void *) (ptrint) &Java_java_lang_Thread_internalExit  },
61 #endif
62         { "yield",         "()V",                  (void *) (ptrint) &Java_java_lang_Thread_yield         },
63 };
64
65
66 /* _Jv_java_lang_Thread_init ***************************************************
67  
68    Register native functions.
69  
70 *******************************************************************************/
71  
72 void _Jv_java_lang_Thread_init(void)
73 {
74         utf *u;
75  
76         u = utf_new_char("java/lang/Thread");
77  
78         native_method_register(u, methods, NATIVE_METHODS_COUNT);
79 }
80
81
82 /*
83  * Class:     java/lang/Thread
84  * Method:    currentThread
85  * Signature: ()Ljava/lang/Thread;
86  */
87 JNIEXPORT java_lang_Thread* JNICALL Java_java_lang_Thread_currentThread(JNIEnv *env, jclass clazz)
88 {
89         return _Jv_java_lang_Thread_currentThread();
90 }
91
92
93 /*
94  * Class:     java/lang/Thread
95  * Method:    setPriority0
96  * Signature: (II)V
97  */
98 JNIEXPORT void JNICALL Java_java_lang_Thread_setPriority0(JNIEnv *env, java_lang_Thread *this, s4 oldPriority, s4 newPriority)
99 {
100         _Jv_java_lang_Thread_setPriority(this, newPriority);
101 }
102
103
104 /*
105  * Class:     java/lang/Thread
106  * Method:    sleep
107  * Signature: (J)V
108  */
109 JNIEXPORT void JNICALL Java_java_lang_Thread_sleep(JNIEnv *env, jclass clazz, s8 millis)
110 {
111         _Jv_java_lang_Thread_sleep(millis);
112 }
113
114
115 /*
116  * Class:     java/lang/Thread
117  * Method:    start0
118  * Signature: ()V
119  */
120 JNIEXPORT void JNICALL Java_java_lang_Thread_start0(JNIEnv *env, java_lang_Thread *this)
121 {
122         _Jv_java_lang_Thread_start(this, 0);
123 }
124
125
126 /*
127  * Class:     java/lang/Thread
128  * Method:    isAlive
129  * Signature: ()Z
130  */
131 JNIEXPORT int32_t JNICALL Java_java_lang_Thread_isAlive(JNIEnv *env, java_lang_Thread *this)
132 {
133 #if defined(ENABLE_THREADS)
134         threadobject *t;
135         bool          result;
136
137         t = (threadobject *) this->vm_thread;
138
139         if (t == NULL)
140                 return 0;
141
142         result = threads_thread_is_alive(t);
143
144         return result;
145 #else
146         /* If threads are disabled, the only thread running is alive. */
147
148         return 1;
149 #endif
150 }
151
152
153 #if 0
154 /*
155  * Class:     java/lang/Thread
156  * Method:    activeCount
157  * Signature: ()I
158  */
159 JNIEXPORT s4 JNICALL Java_java_lang_Thread_activeCount(JNIEnv *env, jclass clazz)
160 {
161 }
162
163
164 /*
165  * Class:     java/lang/Thread
166  * Method:    setPriority0
167  * Signature: (II)V
168  */
169 JNIEXPORT void JNICALL Java_java_lang_Thread_setPriority0(JNIEnv *env, struct java_lang_Thread* this, s4 par1, s4 par2)
170 {
171 }
172
173
174 /*
175  * Class:     java/lang/Thread
176  * Method:    interrupt0
177  * Signature: ()V
178  */
179 JNIEXPORT void JNICALL Java_java_lang_Thread_interrupt0(JNIEnv *env, struct java_lang_Thread* this)
180 {
181 }
182
183
184 /*
185  * Class:     java/lang/Thread
186  * Method:    internalExit
187  * Signature: ()V
188  */
189 JNIEXPORT void JNICALL Java_java_lang_Thread_internalExit(JNIEnv *env, struct java_lang_Thread* this)
190 {
191 }
192 #endif
193
194
195 /*
196  * Class:     java/lang/Thread
197  * Method:    yield
198  * Signature: ()V
199  */
200 JNIEXPORT void JNICALL Java_java_lang_Thread_yield(JNIEnv *env, jclass clazz)
201 {
202 #if defined(ENABLE_THREADS)
203         threads_yield();
204 #endif
205 }
206
207
208 /*
209  * These are local overrides for various environment variables in Emacs.
210  * Please do not remove this and leave it at the end of the file, where
211  * Emacs will automagically detect them.
212  * ---------------------------------------------------------------------
213  * Local variables:
214  * mode: c
215  * indent-tabs-mode: t
216  * c-basic-offset: 4
217  * tab-width: 4
218  * End:
219  * vim:noexpandtab:sw=4:ts=4:
220  */