* src/threads/threads-common.h (threads_thread_get_object): Added.
authorMichael Starzinger <michi@complang.tuwien.ac.at>
Sat, 6 Oct 2007 21:33:39 +0000 (23:33 +0200)
committerMichael Starzinger <michi@complang.tuwien.ac.at>
Sat, 6 Oct 2007 21:33:39 +0000 (23:33 +0200)
(threads_thread_set_object): Added.

* src/threads/threads-common.c: Use above functions throughout the code.

* src/threads/native/threads.c: Likewise.

* src/native/vm/java_lang_Thread.c: Likewise.
(_Jv_java_lang_Thread_start): Fixed compiler warning.
(_Jv_java_lang_Thread_currentThread) [ENABLE_JAVASE]: Fixed for handles.

src/native/vm/java_lang_Thread.c
src/threads/native/threads.c
src/threads/threads-common.c
src/threads/threads-common.h

index 9e9dbac2359aa5ecf81dd29e1c9a07755c1d9743..fb772494435275e67349247b3db08552ad496d13 100644 (file)
@@ -91,7 +91,7 @@ void _Jv_java_lang_Thread_sleep(s8 millis)
 void _Jv_java_lang_Thread_start(java_lang_Thread *this, s8 stacksize)
 {
 #if defined(ENABLE_THREADS)
-       threads_thread_start(this);
+       threads_thread_start((java_handle_t *) this);
 #endif
 }
 
@@ -235,32 +235,39 @@ void _Jv_java_lang_Thread_stop(java_lang_Thread *this, java_lang_Throwable *t)
 java_lang_Thread *_Jv_java_lang_Thread_currentThread(void)
 {
 #if defined(ENABLE_THREADS)
-       threadobject     *thread;
+       threadobject          *thread;
+#endif
+       java_lang_Thread      *t;
+#if defined(ENABLE_JAVASE)
+       java_lang_ThreadGroup *group;
 #endif
-       java_lang_Thread *t;
 
 #if defined(ENABLE_THREADS)
        thread = THREADOBJECT;
 
-       t = LLNI_WRAP(thread->object);
+       t = (java_lang_Thread *) threads_thread_get_object(thread);
 
        if (t == NULL)
                log_text("t ptr is NULL\n");
 
 # if defined(ENABLE_JAVASE)
-       if (LLNI_field_direct(t, group) == NULL) {
+       LLNI_field_get_ref(t, group, group);
+
+       if (group == NULL) {
                /* ThreadGroup of currentThread is not initialized */
 
-               LLNI_field_direct(t, group) = (java_lang_ThreadGroup *)
+               group = (java_lang_ThreadGroup *)
                        native_new_and_init(class_java_lang_ThreadGroup);
 
-               if (LLNI_field_direct(t, group) == NULL)
+               if (group == NULL)
                        log_text("unable to create ThreadGroup");
+
+               LLNI_field_set_ref(t, group, group);
        }
 # endif
 #else
        /* we just return a fake java.lang.Thread object, otherwise we get
-       NullPointerException's in GNU classpath */
+          NullPointerException's in GNU classpath */
 
        t = (java_lang_Thread *) builtin_new(class_java_lang_Thread);
 #endif
index fbb193e0e41136ac8f576ad9cf98dd71d28b5824..8e5d7ba71684fbe33ed03e14ad82de1c962102fc 100644 (file)
@@ -927,7 +927,7 @@ bool threads_init(void)
 
        /* set the object in the internal data structure */
 
-       mainthread->object = LLNI_DIRECT(t);
+       threads_thread_set_object(mainthread, t);
 
 #if defined(ENABLE_INTRP)
        /* create interpreter stack */
@@ -1112,7 +1112,7 @@ static void *threads_startup_thread(void *arg)
 
        /* get the java.lang.Thread object for this thread */
 
-       object = (java_lang_Thread *) LLNI_WRAP(thread->object);
+       object = (java_lang_Thread *) threads_thread_get_object(thread);
 
        /* set our priority */
 
@@ -1388,7 +1388,7 @@ bool threads_attach_current_thread(JavaVMAttachArgs *vm_aargs, bool isdaemon)
        if (t == NULL)
                return false;
 
-       thread->object = LLNI_DIRECT(t);
+       threads_thread_set_object(thread, t);
 
        /* thread is completely initialized */
 
@@ -1444,7 +1444,7 @@ bool threads_attach_current_thread(JavaVMAttachArgs *vm_aargs, bool isdaemon)
                /* get the main thread */
 
                mainthread = threads_list_first();
-               mainthreado = (java_lang_Thread *) LLNI_WRAP(mainthread->object);
+               mainthreado = (java_lang_Thread *) threads_thread_get_object(mainthread);
                group = LLNI_field_direct(mainthreado, group);
 #endif
        }
@@ -1513,7 +1513,7 @@ bool threads_detach_thread(threadobject *t)
 #endif
 
 #if defined(ENABLE_JAVASE)
-       object = (java_lang_Thread *) LLNI_WRAP(t->object);
+       object = (java_lang_Thread *) threads_thread_get_object(t);
 
        LLNI_field_get_ref(object, group, group);
 
index dbede93496094893f6467eba62017a7cec098662..e53c0f5667e0decad97b01dfa059c1090c04b357 100644 (file)
@@ -454,7 +454,7 @@ bool threads_thread_start_internal(utf *name, functionptr f)
        LLNI_field_set_val(object, vm_thread, (java_lang_Object *) t);
 #endif
 
-       t->object = LLNI_DIRECT(object);
+       threads_thread_set_object(t, object);
 
        /* set java.lang.Thread fields */
 
@@ -530,7 +530,7 @@ void threads_thread_start(java_handle_t *object)
 
        /* link the two objects together */
 
-       thread->object = LLNI_DIRECT(object);
+       threads_thread_set_object(thread, object);
 
 #if defined(WITH_CLASSPATH_GNU)
        LLNI_field_get_ref(o, vmThread, vmt);
@@ -568,7 +568,7 @@ void threads_thread_print_info(threadobject *t)
 
        /* the thread may be currently in initalization, don't print it */
 
-       object = (java_lang_Thread *) LLNI_WRAP(t->object);
+       object = (java_lang_Thread *) threads_thread_get_object(t);
 
        if (object != NULL) {
                /* get thread name */
index d1412c786eeeceea2755e4541d430d6bd700b4d6..3cea52547ab049b548479f225eea472d64f6df50 100644 (file)
@@ -33,7 +33,7 @@
 
 #include "vm/global.h"
 
-#include "native/jni.h"
+#include "native/llni.h"
 
 #if defined(ENABLE_THREADS)
 # include "threads/native/threads.h"
@@ -87,6 +87,32 @@ extern bool threads_pthreads_implementation_nptl;
 #endif
 
 
+/* inline functions ***********************************************************/
+
+/* threads_thread_get_object ***************************************************
+
+   Return the java.lang.Thread object for the given thread.
+
+*******************************************************************************/
+
+static inline java_handle_t *threads_thread_get_object(threadobject *t)
+{
+       return LLNI_WRAP(t->object);
+}
+
+
+/* threads_thread_set_object ***************************************************
+
+   Set the java.lang.Thread object for the given thread.
+
+*******************************************************************************/
+
+static inline void threads_thread_set_object(threadobject *t, java_handle_t *object)
+{
+       t->object = LLNI_DIRECT(object);
+}
+
+
 /* function prototypes ********************************************************/
 
 void          threads_preinit(void);