* src/threads/mutex.h: Renamed to...
[cacao.git] / src / threads / thread.h
index 8a1f8979d71ad1abad9faae407d3d5df729efd40..6d4e02e319dfdbc2cdcd5d7736f983edb9049ae6 100644 (file)
 
 #include "config.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #include "vmcore/system.h"
 
+#include "threads/mutex.hpp"
+
 #if defined(ENABLE_THREADS)
 # include "threads/posix/thread-posix.h"
 #else
@@ -148,6 +154,24 @@ 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.
@@ -188,7 +212,38 @@ inline static bool thread_is_attached(threadobject *t)
 
 inline static bool thread_is_interrupted(threadobject *t)
 {
-       return t->interrupted;
+       bool interrupted;
+
+       /* We need the mutex because classpath will call this function when
+          a blocking system call is interrupted. The mutex ensures that it will
+          see the correct value for the interrupted flag. */
+
+       Mutex_lock(t->waitmutex);
+       interrupted = t->interrupted;
+       Mutex_unlock(t->waitmutex);
+
+       return 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);
 }
 
 
@@ -250,19 +305,22 @@ 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);
+bool          thread_attach_current_thread(JavaVMAttachArgs *vm_aargs, bool isdaemon);
+bool          thread_attach_current_external_thread(JavaVMAttachArgs *vm_aargs, bool isdaemon);
+bool          thread_detach_current_thread(void);
+
+bool          thread_detach_current_external_thread(void);
 
 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);
@@ -293,6 +351,10 @@ void          threads_yield(void);
 
 #endif /* ENABLE_THREADS */
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* _THREAD_H */