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.h"
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"
43 #include "vmcore/javaobjects.hpp"
46 // Native functions are exported as C functions.
50 * Class: java/lang/Thread
51 * Method: currentThread
52 * Signature: ()Ljava/lang/Thread;
54 JNIEXPORT jobject JNICALL Java_java_lang_Thread_currentThread(JNIEnv *env, jclass clazz)
56 return (jobject) thread_get_current_object();
61 * Class: java/lang/Thread
62 * Method: setPriority0
65 JNIEXPORT void JNICALL Java_java_lang_Thread_setPriority0(JNIEnv *env, jobject _this, jint oldPriority, jint newPriority)
67 #if defined(ENABLE_THREADS)
68 java_lang_Thread jlt(_this);
69 threadobject* t = jlt.get_vm_thread();
71 // The threadobject is null when a thread is created in Java. The
72 // priority is set later during startup.
76 threads_set_thread_priority(t->tid, newPriority);
82 * Class: java/lang/Thread
86 JNIEXPORT void JNICALL Java_java_lang_Thread_sleep(JNIEnv *env, jclass clazz, jlong millis)
88 #if defined(ENABLE_THREADS)
89 threads_sleep(millis, 0);
95 * Class: java/lang/Thread
99 JNIEXPORT void JNICALL Java_java_lang_Thread_start0(JNIEnv *env, jobject _this)
101 #if defined(ENABLE_THREADS)
102 java_lang_Thread jlt(_this);
103 threads_thread_start(jlt.get_handle());
109 * Class: java/lang/Thread
113 JNIEXPORT jboolean JNICALL Java_java_lang_Thread_isAlive(JNIEnv *env, jobject _this)
115 #if defined(ENABLE_THREADS)
116 java_lang_Thread jlt(_this);
117 threadobject* t = jlt.get_vm_thread();
122 bool result = threads_thread_is_alive(t);
126 // If threads are disabled, the only thread running is alive.
134 * Class: java/lang/Thread
135 * Method: activeCount
138 JNIEXPORT s4 JNICALL Java_java_lang_Thread_activeCount(JNIEnv *env, jclass clazz)
144 * Class: java/lang/Thread
148 JNIEXPORT void JNICALL Java_java_lang_Thread_interrupt0(JNIEnv *env, jobject _this)
154 * Class: java/lang/Thread
155 * Method: internalExit
158 JNIEXPORT void JNICALL Java_java_lang_Thread_internalExit(JNIEnv *env, jobject _this)
165 * Class: java/lang/Thread
169 JNIEXPORT void JNICALL Java_java_lang_Thread_yield(JNIEnv *env, jclass clazz)
171 #if defined(ENABLE_THREADS)
179 /* native methods implemented by this file ************************************/
181 static JNINativeMethod methods[] = {
182 { (char*) "currentThread", (char*) "()Ljava/lang/Thread;", (void*) (uintptr_t) &Java_java_lang_Thread_currentThread },
183 { (char*) "setPriority0", (char*) "(II)V", (void*) (uintptr_t) &Java_java_lang_Thread_setPriority0 },
184 { (char*) "sleep", (char*) "(J)V", (void*) (uintptr_t) &Java_java_lang_Thread_sleep },
185 { (char*) "start0", (char*) "()V", (void*) (uintptr_t) &Java_java_lang_Thread_start0 },
186 { (char*) "isAlive", (char*) "()Z", (void*) (uintptr_t) &Java_java_lang_Thread_isAlive },
188 { (char*) "activeCount", (char*) "()I", (void*) (uintptr_t) &Java_java_lang_Thread_activeCount },
189 { (char*) "setPriority0", (char*) "(II)V", (void*) (uintptr_t) &Java_java_lang_Thread_setPriority0 },
190 { (char*) "interrupt0", (char*) "()V", (void*) (uintptr_t) &Java_java_lang_Thread_interrupt0 },
191 { (char*) "internalExit", (char*) "()V", (void*) (uintptr_t) &Java_java_lang_Thread_internalExit },
193 { (char*) "yield", (char*) "()V", (void*) (uintptr_t) &Java_java_lang_Thread_yield },
197 /* _Jv_java_lang_Thread_init ***************************************************
199 Register native functions.
201 *******************************************************************************/
205 void _Jv_java_lang_Thread_init(void)
209 u = utf_new_char("java/lang/Thread");
211 native_method_register(u, methods, NATIVE_METHODS_COUNT);
217 * These are local overrides for various environment variables in Emacs.
218 * Please do not remove this and leave it at the end of the file, where
219 * Emacs will automagically detect them.
220 * ---------------------------------------------------------------------
223 * indent-tabs-mode: t
227 * vim:noexpandtab:sw=4:ts=4: