1 /* src/native/vm/cldc1.1/java_lang_Thread.cpp
3 Copyright (C) 2006, 2007, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
30 #include "native/jni.hpp"
31 #include "native/native.h"
33 #if defined(ENABLE_JNI_HEADERS)
34 # include "native/include/java_lang_Thread.h"
37 #include "threads/thread.hpp"
39 #include "toolbox/logging.h"
41 #include "vm/builtin.h"
42 #include "vm/javaobjects.hpp"
45 // Native functions are exported as C functions.
49 * Class: java/lang/Thread
50 * Method: currentThread
51 * Signature: ()Ljava/lang/Thread;
53 JNIEXPORT jobject JNICALL Java_java_lang_Thread_currentThread(JNIEnv *env, jclass clazz)
55 return (jobject) thread_get_current_object();
60 * Class: java/lang/Thread
61 * Method: setPriority0
64 JNIEXPORT void JNICALL Java_java_lang_Thread_setPriority0(JNIEnv *env, jobject _this, jint oldPriority, jint newPriority)
66 #if defined(ENABLE_THREADS)
67 java_lang_Thread jlt(_this);
68 threadobject* t = jlt.get_vm_thread();
70 // The threadobject is null when a thread is created in Java. The
71 // priority is set later during startup.
75 threads_set_thread_priority(t->tid, newPriority);
81 * Class: java/lang/Thread
85 JNIEXPORT void JNICALL Java_java_lang_Thread_sleep(JNIEnv *env, jclass clazz, jlong millis)
87 #if defined(ENABLE_THREADS)
88 threads_sleep(millis, 0);
94 * Class: java/lang/Thread
98 JNIEXPORT void JNICALL Java_java_lang_Thread_start0(JNIEnv *env, jobject _this)
100 #if defined(ENABLE_THREADS)
101 java_lang_Thread jlt(_this);
102 threads_thread_start(jlt.get_handle());
108 * Class: java/lang/Thread
112 JNIEXPORT jboolean JNICALL Java_java_lang_Thread_isAlive(JNIEnv *env, jobject _this)
114 #if defined(ENABLE_THREADS)
115 java_lang_Thread jlt(_this);
116 threadobject* t = jlt.get_vm_thread();
121 bool result = threads_thread_is_alive(t);
125 // If threads are disabled, the only thread running is alive.
133 * Class: java/lang/Thread
134 * Method: activeCount
137 JNIEXPORT s4 JNICALL Java_java_lang_Thread_activeCount(JNIEnv *env, jclass clazz)
143 * Class: java/lang/Thread
147 JNIEXPORT void JNICALL Java_java_lang_Thread_interrupt0(JNIEnv *env, jobject _this)
153 * Class: java/lang/Thread
154 * Method: internalExit
157 JNIEXPORT void JNICALL Java_java_lang_Thread_internalExit(JNIEnv *env, jobject _this)
164 * Class: java/lang/Thread
168 JNIEXPORT void JNICALL Java_java_lang_Thread_yield(JNIEnv *env, jclass clazz)
170 #if defined(ENABLE_THREADS)
178 /* native methods implemented by this file ************************************/
180 static JNINativeMethod methods[] = {
181 { (char*) "currentThread", (char*) "()Ljava/lang/Thread;", (void*) (uintptr_t) &Java_java_lang_Thread_currentThread },
182 { (char*) "setPriority0", (char*) "(II)V", (void*) (uintptr_t) &Java_java_lang_Thread_setPriority0 },
183 { (char*) "sleep", (char*) "(J)V", (void*) (uintptr_t) &Java_java_lang_Thread_sleep },
184 { (char*) "start0", (char*) "()V", (void*) (uintptr_t) &Java_java_lang_Thread_start0 },
185 { (char*) "isAlive", (char*) "()Z", (void*) (uintptr_t) &Java_java_lang_Thread_isAlive },
187 { (char*) "activeCount", (char*) "()I", (void*) (uintptr_t) &Java_java_lang_Thread_activeCount },
188 { (char*) "setPriority0", (char*) "(II)V", (void*) (uintptr_t) &Java_java_lang_Thread_setPriority0 },
189 { (char*) "interrupt0", (char*) "()V", (void*) (uintptr_t) &Java_java_lang_Thread_interrupt0 },
190 { (char*) "internalExit", (char*) "()V", (void*) (uintptr_t) &Java_java_lang_Thread_internalExit },
192 { (char*) "yield", (char*) "()V", (void*) (uintptr_t) &Java_java_lang_Thread_yield },
196 /* _Jv_java_lang_Thread_init ***************************************************
198 Register native functions.
200 *******************************************************************************/
204 void _Jv_java_lang_Thread_init(void)
208 u = utf_new_char("java/lang/Thread");
210 native_method_register(u, methods, NATIVE_METHODS_COUNT);
216 * These are local overrides for various environment variables in Emacs.
217 * Please do not remove this and leave it at the end of the file, where
218 * Emacs will automagically detect them.
219 * ---------------------------------------------------------------------
222 * indent-tabs-mode: t
226 * vim:noexpandtab:sw=4:ts=4: