Proper x86_64 mnemonics
[cacao.git] / src / threads / thread.h
index 7de0b1d9193e789b04df5b119499ef5616e6d26a..50099e30b5eaafce515a7e1c6fcf0a52e6bb8465 100644 (file)
 */
 
 
-#ifndef _THREADS_COMMON_H
-#define _THREADS_COMMON_H
+#ifndef _THREAD_H
+#define _THREAD_H
 
 #include "config.h"
 
+#include "vmcore/system.h"
+
 #if defined(ENABLE_THREADS)
 # include "threads/posix/thread-posix.h"
 #else
-# include "threads/none/threads.h"
+# include "threads/none/thread-none.h"
 #endif
 
 #include "vm/types.h"
@@ -72,7 +74,7 @@
        do { \
                if (opt_DebugThreads) { \
                        printf("[Thread %-16s: ", message); \
-                       threads_thread_print_info(thread); \
+                       thread_print_info(thread); \
                        printf("]\n"); \
                } \
        } while (0)
@@ -83,8 +85,6 @@
 
 /* global variables ***********************************************************/
 
-extern methodinfo *thread_method_init;
-
 #if defined(__LINUX__)
 /* XXX Remove for exact-GC. */
 extern bool threads_pthreads_implementation_nptl;
@@ -93,13 +93,19 @@ extern bool threads_pthreads_implementation_nptl;
 
 /* inline functions ***********************************************************/
 
-/* threads_thread_get_object ***************************************************
+/* thread_get_object ***********************************************************
+
+   Return the Java for the given thread.
+
+   ARGUMENTS:
+       t ... thread
 
-   Return the java.lang.Thread object for the given thread.
+   RETURN:
+       the Java object
 
 *******************************************************************************/
 
-static inline java_handle_t *threads_thread_get_object(threadobject *t)
+inline static java_handle_t *thread_get_object(threadobject *t)
 {
        return LLNI_WRAP(t->object);
 }
@@ -107,17 +113,21 @@ static inline java_handle_t *threads_thread_get_object(threadobject *t)
 
 /* threads_thread_set_object ***************************************************
 
-   Set the java.lang.Thread object for the given thread.
+   Set the Java object for the given thread.
+
+   ARGUMENTS:
+       t ... thread
+          o ... Java object
 
 *******************************************************************************/
 
-static inline void threads_thread_set_object(threadobject *t, java_handle_t *object)
+inline static void thread_set_object(threadobject *t, java_handle_t *o)
 {
-       t->object = LLNI_DIRECT(object);
+       t->object = LLNI_DIRECT(o);
 }
 
 
-/* threads_get_current_object **************************************************
+/* thread_get_current_object **************************************************
 
    Return the Java object of the current thread.
    
@@ -126,21 +136,43 @@ static inline void threads_thread_set_object(threadobject *t, java_handle_t *obj
 
 *******************************************************************************/
 
-inline static java_handle_t *threads_get_current_object(void)
+inline static java_handle_t *thread_get_current_object(void)
 {
        threadobject  *t;
        java_handle_t *o;
 
        t = THREADOBJECT;
-       o = threads_thread_get_object(t);
+       o = thread_get_object(t);
 
        return o;
 }
 
+
+/* cacaothread_get_state *******************************************************
+
+   Returns the current state of the given thread.
+
+   ARGUMENTS:
+       t ... the thread to check
+
+   RETURN:
+       thread state
+
+*******************************************************************************/
+
+inline static int cacaothread_get_state(threadobject *t)
+{
+       return t->state;
+}
+
+
 /* thread_is_attached **********************************************************
 
    Returns if the given thread is attached to the VM.
 
+   ARGUMENTS:
+       t ... the thread to check
+
    RETURN:
        true .... the thread is attached to the VM
        false ... the thread is not
@@ -151,7 +183,7 @@ inline static bool thread_is_attached(threadobject *t)
 {
        java_handle_t *o;
 
-       o = threads_thread_get_object(t);
+       o = thread_get_object(t);
 
        if (o != NULL)
                return true;
@@ -160,6 +192,67 @@ inline static bool thread_is_attached(threadobject *t)
 }
 
 
+/* thread_is_interrupted *******************************************************
+
+   Check if the given thread has been interrupted.
+
+   ARGUMENTS:
+       t ... the thread to check
+
+   RETURN VALUE:
+      true, if the given thread had been interrupted
+
+*******************************************************************************/
+
+inline static bool thread_is_interrupted(threadobject *t)
+{
+       return t->interrupted;
+}
+
+
+/* thread_set_interrupted ******************************************************
+
+   Set the interrupted flag to the given value.
+
+   ARGUMENTS:
+       interrupted ... value to set
+
+*******************************************************************************/
+
+inline static void thread_set_interrupted(threadobject *t, bool interrupted)
+{
+       mutex_lock(&t->waitmutex);
+
+       /* Set interrupted flag. */
+
+       t->interrupted = interrupted;
+
+       mutex_unlock(&t->waitmutex);
+}
+
+
+/* thread_is_daemon ************************************************************
+
+   Returns if the given thread is a daemon thread.
+
+   ARGUMENTS:
+       t ... the thread to check
+
+   RETURN:
+       true .... the thread is a daemon thread
+       false ... the thread is not
+
+*******************************************************************************/
+
+inline static bool thread_is_daemon(threadobject *t)
+{
+       if (t->flags & THREAD_FLAG_DAEMON)
+               return true;
+       else
+               return false;
+}
+
+
 /* thread_current_is_attached **************************************************
 
    Returns if the current thread is attached to the VM.
@@ -175,7 +268,11 @@ inline static bool thread_current_is_attached(void)
        threadobject  *t;
        bool           result;
 
-       t      = THREADOBJECT;
+       t = thread_get_current();
+
+       if (t == NULL)
+               return false;
+
        result = thread_is_attached(t);
 
        return result;
@@ -187,31 +284,28 @@ inline static bool thread_current_is_attached(void)
 void          threads_preinit(void);
 void          threads_init(void);
 
-threadobject *threads_thread_new(void);
-void          threads_thread_free(threadobject *t);
+void          thread_free(threadobject *t);
 
 bool          threads_thread_start_internal(utf *name, functionptr f);
 void          threads_thread_start(java_handle_t *object);
 
 bool          threads_attach_current_thread(JavaVMAttachArgs *vm_aargs, bool isdaemon);
 
-void          threads_thread_print_info(threadobject *t);
+void          thread_fprint_name(threadobject *t, FILE *stream);
+void          thread_print_info(threadobject *t);
 
 intptr_t      threads_get_current_tid(void);
 
-void          threads_thread_state_runnable(threadobject *t);
-void          threads_thread_state_waiting(threadobject *t);
-void          threads_thread_state_timed_waiting(threadobject *t);
-void          threads_thread_state_terminated(threadobject *t);
+void          thread_set_state_runnable(threadobject *t);
+void          thread_set_state_waiting(threadobject *t);
+void          thread_set_state_timed_waiting(threadobject *t);
+void          thread_set_state_terminated(threadobject *t);
 
-utf          *threads_thread_get_state(threadobject *t);
 threadobject *thread_get_thread(java_handle_t *h);
 
 bool          threads_thread_is_alive(threadobject *t);
 
 void          threads_dump(void);
-void          threads_thread_print_stacktrace(threadobject *thread);
-void          threads_print_stacktrace(void);
 
 
 /* implementation specific functions */
@@ -237,7 +331,7 @@ void          threads_yield(void);
 
 #endif /* ENABLE_THREADS */
 
-#endif /* _THREADS_COMMON_H */
+#endif /* _THREAD_H */
 
 
 /*