* src/native/jni.c (_Jv_JNI_FindClass): Renamed to jni_FindClass, call
[cacao.git] / src / native / vm / cldc1.1 / java_lang_Thread.c
index ea69d0e310d32a5b6fe0af79be09641fb04f3c13..da9ffd01a604c358179e4883a802ab22e1945a0f 100644 (file)
@@ -1,9 +1,7 @@
 /* src/native/vm/cldc1.1/java_lang_Thread.c
 
-   Copyright (C) 2006, 2007 R. Grafl, A. Krall, C. Kruegel, C. Oates,
-   R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
-   C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
-   Institut f. Computersprachen - TU Wien
+   Copyright (C) 2006, 2007, 2008
+   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
 
    This file is part of CACAO.
 
@@ -26,6 +24,9 @@
 
 
 #include "config.h"
+
+#include <stdint.h>
+
 #include "vm/types.h"
 
 #include "native/jni.h"
@@ -33,9 +34,7 @@
 
 #include "native/include/java_lang_Thread.h"
 
-#include "native/vm/java_lang_Thread.h"
-
-#include "threads/threads-common.h"
+#include "threads/thread.h"
 
 #include "toolbox/logging.h"
 
@@ -83,7 +82,11 @@ void _Jv_java_lang_Thread_init(void)
  */
 JNIEXPORT java_lang_Thread* JNICALL Java_java_lang_Thread_currentThread(JNIEnv *env, jclass clazz)
 {
-       return _Jv_java_lang_Thread_currentThread();
+       java_lang_Thread *to;
+
+       to = (java_lang_Thread *) thread_get_current_object();
+
+       return to;
 }
 
 
@@ -94,7 +97,19 @@ JNIEXPORT java_lang_Thread* JNICALL Java_java_lang_Thread_currentThread(JNIEnv *
  */
 JNIEXPORT void JNICALL Java_java_lang_Thread_setPriority0(JNIEnv *env, java_lang_Thread *this, s4 oldPriority, s4 newPriority)
 {
-       _Jv_java_lang_Thread_setPriority(this, newPriority);
+#if defined(ENABLE_THREADS)
+       threadobject *t;
+
+       t = (threadobject *) this->vm_thread;
+
+       /* The threadobject is null when a thread is created in Java. The
+          priority is set later during startup. */
+
+       if (t == NULL)
+               return;
+
+       threads_set_thread_priority(t->tid, newPriority);
+#endif
 }
 
 
@@ -105,7 +120,9 @@ JNIEXPORT void JNICALL Java_java_lang_Thread_setPriority0(JNIEnv *env, java_lang
  */
 JNIEXPORT void JNICALL Java_java_lang_Thread_sleep(JNIEnv *env, jclass clazz, s8 millis)
 {
-       _Jv_java_lang_Thread_sleep(millis);
+#if defined(ENABLE_THREADS)
+       threads_sleep(millis, 0);
+#endif
 }
 
 
@@ -116,7 +133,9 @@ JNIEXPORT void JNICALL Java_java_lang_Thread_sleep(JNIEnv *env, jclass clazz, s8
  */
 JNIEXPORT void JNICALL Java_java_lang_Thread_start0(JNIEnv *env, java_lang_Thread *this)
 {
-       _Jv_java_lang_Thread_start(this, 0);
+#if defined(ENABLE_THREADS)
+       threads_thread_start((java_handle_t *) this);
+#endif
 }
 
 
@@ -125,9 +144,25 @@ JNIEXPORT void JNICALL Java_java_lang_Thread_start0(JNIEnv *env, java_lang_Threa
  * Method:    isAlive
  * Signature: ()Z
  */
-JNIEXPORT s4 JNICALL Java_java_lang_Thread_isAlive(JNIEnv *env, java_lang_Thread *this)
+JNIEXPORT int32_t JNICALL Java_java_lang_Thread_isAlive(JNIEnv *env, java_lang_Thread *this)
 {
-       return _Jv_java_lang_Thread_isAlive(this);
+#if defined(ENABLE_THREADS)
+       threadobject *t;
+       bool          result;
+
+       t = (threadobject *) this->vm_thread;
+
+       if (t == NULL)
+               return 0;
+
+       result = threads_thread_is_alive(t);
+
+       return result;
+#else
+       /* If threads are disabled, the only thread running is alive. */
+
+       return 1;
+#endif
 }