Fix mysterious unremovable file part 2 ?
[cacao.git] / src / threads / thread.h
index e1152878eaec17200019f290b7b0640ca2eba5e1..50099e30b5eaafce515a7e1c6fcf0a52e6bb8465 100644 (file)
@@ -23,8 +23,8 @@
 */
 
 
-#ifndef _THREADS_COMMON_H
-#define _THREADS_COMMON_H
+#ifndef _THREAD_H
+#define _THREAD_H
 
 #include "config.h"
 
@@ -33,7 +33,7 @@
 #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"
@@ -74,7 +74,7 @@
        do { \
                if (opt_DebugThreads) { \
                        printf("[Thread %-16s: ", message); \
-                       threads_thread_print_info(thread); \
+                       thread_print_info(thread); \
                        printf("]\n"); \
                } \
        } while (0)
@@ -148,10 +148,31 @@ inline static java_handle_t *thread_get_current_object(void)
 }
 
 
+/* 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
@@ -171,10 +192,52 @@ 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
@@ -205,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;
@@ -225,23 +292,20 @@ void          threads_thread_start(java_handle_t *object);
 bool          threads_attach_current_thread(JavaVMAttachArgs *vm_aargs, bool isdaemon);
 
 void          thread_fprint_name(threadobject *t, FILE *stream);
-void          threads_thread_print_info(threadobject *t);
+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 */
@@ -267,7 +331,7 @@ void          threads_yield(void);
 
 #endif /* ENABLE_THREADS */
 
-#endif /* _THREADS_COMMON_H */
+#endif /* _THREAD_H */
 
 
 /*