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"
35 #include "native/include/java_lang_Thread.h"
38 #include "threads/thread.hpp"
40 #include "toolbox/logging.h"
42 #include "vm/builtin.h"
45 /* native methods implemented by this file ************************************/
47 static JNINativeMethod methods[] = {
48 { (char*) "currentThread", (char*) "()Ljava/lang/Thread;", (void*) (uintptr_t) &Java_java_lang_Thread_currentThread },
49 { (char*) "setPriority0", (char*) "(II)V", (void*) (uintptr_t) &Java_java_lang_Thread_setPriority0 },
50 { (char*) "sleep", (char*) "(J)V", (void*) (uintptr_t) &Java_java_lang_Thread_sleep },
51 { (char*) "start0", (char*) "()V", (void*) (uintptr_t) &Java_java_lang_Thread_start0 },
52 { (char*) "isAlive", (char*) "()Z", (void*) (uintptr_t) &Java_java_lang_Thread_isAlive },
54 { (char*) "activeCount", (char*) "()I", (void*) (uintptr_t) &Java_java_lang_Thread_activeCount },
55 { (char*) "setPriority0", (char*) "(II)V", (void*) (uintptr_t) &Java_java_lang_Thread_setPriority0 },
56 { (char*) "interrupt0", (char*) "()V", (void*) (uintptr_t) &Java_java_lang_Thread_interrupt0 },
57 { (char*) "internalExit", (char*) "()V", (void*) (uintptr_t) &Java_java_lang_Thread_internalExit },
59 { (char*) "yield", (char*) "()V", (void*) (uintptr_t) &Java_java_lang_Thread_yield },
63 /* _Jv_java_lang_Thread_init ***************************************************
65 Register native functions.
67 *******************************************************************************/
71 void _Jv_java_lang_Thread_init(void)
75 u = utf_new_char("java/lang/Thread");
77 native_method_register(u, methods, NATIVE_METHODS_COUNT);
82 // Native functions are exported as C functions.
86 * Class: java/lang/Thread
87 * Method: currentThread
88 * Signature: ()Ljava/lang/Thread;
90 JNIEXPORT java_lang_Thread* JNICALL Java_java_lang_Thread_currentThread(JNIEnv *env, jclass clazz)
94 to = (java_lang_Thread *) thread_get_current_object();
101 * Class: java/lang/Thread
102 * Method: setPriority0
105 JNIEXPORT void JNICALL Java_java_lang_Thread_setPriority0(JNIEnv *env, java_lang_Thread *_this, s4 oldPriority, s4 newPriority)
107 #if defined(ENABLE_THREADS)
110 t = (threadobject *) _this->vm_thread;
112 /* The threadobject is null when a thread is created in Java. The
113 priority is set later during startup. */
118 threads_set_thread_priority(t->tid, newPriority);
124 * Class: java/lang/Thread
128 JNIEXPORT void JNICALL Java_java_lang_Thread_sleep(JNIEnv *env, jclass clazz, s8 millis)
130 #if defined(ENABLE_THREADS)
131 threads_sleep(millis, 0);
137 * Class: java/lang/Thread
141 JNIEXPORT void JNICALL Java_java_lang_Thread_start0(JNIEnv *env, java_lang_Thread *_this)
143 #if defined(ENABLE_THREADS)
144 threads_thread_start((java_handle_t *) _this);
150 * Class: java/lang/Thread
154 JNIEXPORT int32_t JNICALL Java_java_lang_Thread_isAlive(JNIEnv *env, java_lang_Thread *_this)
156 #if defined(ENABLE_THREADS)
160 t = (threadobject *) _this->vm_thread;
165 result = threads_thread_is_alive(t);
169 /* If threads are disabled, the only thread running is alive. */
178 * Class: java/lang/Thread
179 * Method: activeCount
182 JNIEXPORT s4 JNICALL Java_java_lang_Thread_activeCount(JNIEnv *env, jclass clazz)
188 * Class: java/lang/Thread
189 * Method: setPriority0
192 JNIEXPORT void JNICALL Java_java_lang_Thread_setPriority0(JNIEnv *env, struct java_lang_Thread* _this, s4 par1, s4 par2)
198 * Class: java/lang/Thread
202 JNIEXPORT void JNICALL Java_java_lang_Thread_interrupt0(JNIEnv *env, struct java_lang_Thread* _this)
208 * Class: java/lang/Thread
209 * Method: internalExit
212 JNIEXPORT void JNICALL Java_java_lang_Thread_internalExit(JNIEnv *env, struct java_lang_Thread* _this)
219 * Class: java/lang/Thread
223 JNIEXPORT void JNICALL Java_java_lang_Thread_yield(JNIEnv *env, jclass clazz)
225 #if defined(ENABLE_THREADS)
234 * These are local overrides for various environment variables in Emacs.
235 * Please do not remove this and leave it at the end of the file, where
236 * Emacs will automagically detect them.
237 * ---------------------------------------------------------------------
240 * indent-tabs-mode: t
244 * vim:noexpandtab:sw=4:ts=4: