1 /* src/native/vm/cldc1.1/java_lang_Thread.c
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
32 #include "native/jni.h"
33 #include "native/native.h"
35 #include "native/include/java_lang_Thread.h"
37 #include "threads/thread.hpp"
39 #include "toolbox/logging.h"
41 #include "vm/builtin.h"
44 /* native methods implemented by this file ************************************/
46 static JNINativeMethod methods[] = {
47 { "currentThread", "()Ljava/lang/Thread;", (void *) (ptrint) &Java_java_lang_Thread_currentThread },
48 { "setPriority0", "(II)V", (void *) (ptrint) &Java_java_lang_Thread_setPriority0 },
49 { "sleep", "(J)V", (void *) (ptrint) &Java_java_lang_Thread_sleep },
50 { "start0", "()V", (void *) (ptrint) &Java_java_lang_Thread_start0 },
51 { "isAlive", "()Z", (void *) (ptrint) &Java_java_lang_Thread_isAlive },
53 { "activeCount", "()I", (void *) (ptrint) &Java_java_lang_Thread_activeCount },
54 { "setPriority0", "(II)V", (void *) (ptrint) &Java_java_lang_Thread_setPriority0 },
55 { "interrupt0", "()V", (void *) (ptrint) &Java_java_lang_Thread_interrupt0 },
56 { "internalExit", "()V", (void *) (ptrint) &Java_java_lang_Thread_internalExit },
58 { "yield", "()V", (void *) (ptrint) &Java_java_lang_Thread_yield },
62 /* _Jv_java_lang_Thread_init ***************************************************
64 Register native functions.
66 *******************************************************************************/
68 void _Jv_java_lang_Thread_init(void)
72 u = utf_new_char("java/lang/Thread");
74 native_method_register(u, methods, NATIVE_METHODS_COUNT);
79 * Class: java/lang/Thread
80 * Method: currentThread
81 * Signature: ()Ljava/lang/Thread;
83 JNIEXPORT java_lang_Thread* JNICALL Java_java_lang_Thread_currentThread(JNIEnv *env, jclass clazz)
87 to = (java_lang_Thread *) thread_get_current_object();
94 * Class: java/lang/Thread
95 * Method: setPriority0
98 JNIEXPORT void JNICALL Java_java_lang_Thread_setPriority0(JNIEnv *env, java_lang_Thread *this, s4 oldPriority, s4 newPriority)
100 #if defined(ENABLE_THREADS)
103 t = (threadobject *) this->vm_thread;
105 /* The threadobject is null when a thread is created in Java. The
106 priority is set later during startup. */
111 threads_set_thread_priority(t->tid, newPriority);
117 * Class: java/lang/Thread
121 JNIEXPORT void JNICALL Java_java_lang_Thread_sleep(JNIEnv *env, jclass clazz, s8 millis)
123 #if defined(ENABLE_THREADS)
124 threads_sleep(millis, 0);
130 * Class: java/lang/Thread
134 JNIEXPORT void JNICALL Java_java_lang_Thread_start0(JNIEnv *env, java_lang_Thread *this)
136 #if defined(ENABLE_THREADS)
137 threads_thread_start((java_handle_t *) this);
143 * Class: java/lang/Thread
147 JNIEXPORT int32_t JNICALL Java_java_lang_Thread_isAlive(JNIEnv *env, java_lang_Thread *this)
149 #if defined(ENABLE_THREADS)
153 t = (threadobject *) this->vm_thread;
158 result = threads_thread_is_alive(t);
162 /* If threads are disabled, the only thread running is alive. */
171 * Class: java/lang/Thread
172 * Method: activeCount
175 JNIEXPORT s4 JNICALL Java_java_lang_Thread_activeCount(JNIEnv *env, jclass clazz)
181 * Class: java/lang/Thread
182 * Method: setPriority0
185 JNIEXPORT void JNICALL Java_java_lang_Thread_setPriority0(JNIEnv *env, struct java_lang_Thread* this, s4 par1, s4 par2)
191 * Class: java/lang/Thread
195 JNIEXPORT void JNICALL Java_java_lang_Thread_interrupt0(JNIEnv *env, struct java_lang_Thread* this)
201 * Class: java/lang/Thread
202 * Method: internalExit
205 JNIEXPORT void JNICALL Java_java_lang_Thread_internalExit(JNIEnv *env, struct java_lang_Thread* this)
212 * Class: java/lang/Thread
216 JNIEXPORT void JNICALL Java_java_lang_Thread_yield(JNIEnv *env, jclass clazz)
218 #if defined(ENABLE_THREADS)
225 * These are local overrides for various environment variables in Emacs.
226 * Please do not remove this and leave it at the end of the file, where
227 * Emacs will automagically detect them.
228 * ---------------------------------------------------------------------
231 * indent-tabs-mode: t
235 * vim:noexpandtab:sw=4:ts=4: