* src/threads/posix/thread-posix.cpp, src/threads/thread.cpp,
[cacao.git] / src / threads / thread.hpp
index 3af46159ca3c0f049e815e6f56cc60c0b6768e71..e5a372d754673a425d026932dd07de2d2269a8ec 100644 (file)
@@ -1,6 +1,6 @@
 /* src/threads/thread.hpp - machine independent thread functions
 
-   Copyright (C) 2007, 2008
+   Copyright (C) 1996-2011
    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
 
    This file is part of CACAO.
 
 #include "config.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include "vmcore/os.hpp"
-
-#include "threads/mutex.hpp"
+#include "vm/types.h"
 
+// Include early to get threadobject.
 #if defined(ENABLE_THREADS)
 # include "threads/posix/thread-posix.hpp"
 #else
 # include "threads/none/thread-none.h"
 #endif
 
-#include "vm/types.h"
+#include "vm/os.hpp"
 
-#include "vm/global.h"
-
-#include "native/jni.h"
 #include "native/llni.h"
 
-#include "vmcore/utf8.h"
+#include "threads/mutex.hpp"
+
+#include "vm/global.h"
+#include "vm/utf8.h"
 
 
 /* only define the following stuff with thread enabled ************************/
@@ -64,6 +59,8 @@ extern "C" {
 #define THREAD_STATE_WAITING          3
 #define THREAD_STATE_TIMED_WAITING    4
 #define THREAD_STATE_TERMINATED       5
+#define THREAD_STATE_PARKED           6
+#define THREAD_STATE_TIMED_PARKED     7
 
 
 /* thread priorities **********************************************************/
@@ -97,6 +94,10 @@ extern bool threads_pthreads_implementation_nptl;
 #endif
 
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /* inline functions ***********************************************************/
 
 /* thread_get_object ***********************************************************
@@ -191,67 +192,7 @@ inline static bool thread_is_attached(threadobject *t)
 
        o = thread_get_object(t);
 
-       if (o != NULL)
-               return true;
-       else
-               return false;
-}
-
-
-/* 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)
-{
-       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. */
-
-#ifdef __cplusplus
-       t->waitmutex->lock();
-       interrupted = t->interrupted;
-       t->waitmutex->unlock();
-#else
-       Mutex_lock(t->waitmutex);
-       interrupted = t->interrupted;
-       Mutex_unlock(t->waitmutex);
-#endif
-
-       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)
-{
-#ifdef __cplusplus
-       t->waitmutex->lock();
-       t->interrupted = interrupted;
-       t->waitmutex->unlock();
-#else
-       Mutex_lock(t->waitmutex);
-       t->interrupted = interrupted;
-       Mutex_unlock(t->waitmutex);
-#endif
+       return o != NULL;
 }
 
 
@@ -270,10 +211,7 @@ inline static void thread_set_interrupted(threadobject *t, bool interrupted)
 
 inline static bool thread_is_daemon(threadobject *t)
 {
-       if (t->flags & THREAD_FLAG_DAEMON)
-               return true;
-       else
-               return false;
+       return (t->flags & THREAD_FLAG_DAEMON) != 0;
 }
 
 
@@ -290,16 +228,13 @@ inline static bool thread_is_daemon(threadobject *t)
 inline static bool thread_current_is_attached(void)
 {
        threadobject  *t;
-       bool           result;
 
        t = thread_get_current();
 
        if (t == NULL)
                return false;
 
-       result = thread_is_attached(t);
-
-       return result;
+       return thread_is_attached(t);
 }
 
 
@@ -327,14 +262,15 @@ intptr_t      threads_get_current_tid(void);
 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_parked(threadobject *t);
+void          thread_set_state_timed_parked(threadobject *t);
 void          thread_set_state_terminated(threadobject *t);
 
 threadobject *thread_get_thread(java_handle_t *h);
 
 bool          threads_thread_is_alive(threadobject *t);
-
-void          threads_dump(void);
-
+bool          thread_is_interrupted(threadobject *t);
+void          thread_set_interrupted(threadobject *t, bool interrupted);
 
 /* implementation specific functions */
 
@@ -349,22 +285,33 @@ void          threads_mutex_gc_unlock(void);
 void          threads_mutex_join_lock(void);
 void          threads_mutex_join_unlock(void);
 
-void          threads_impl_thread_init(threadobject *t);
 void          threads_impl_thread_clear(threadobject *t);
 void          threads_impl_thread_reuse(threadobject *t);
-void          threads_impl_thread_free(threadobject *t);
 void          threads_impl_thread_start(threadobject *thread, functionptr f);
 
 void          threads_yield(void);
 
-#endif /* ENABLE_THREADS */
-
 #ifdef __cplusplus
 }
 #endif
 
+#endif /* ENABLE_THREADS */
+
 #endif // _THREAD_HPP
 
+void          thread_handle_set_priority(java_handle_t *th, int);
+bool          thread_handle_is_interrupted(java_handle_t *th);
+void          thread_handle_interrupt(java_handle_t *th);
+int           thread_handle_get_state(java_handle_t *th);
+
+#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
+#include "thread-classpath.hpp"
+#elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
+#include "thread-openjdk.hpp"
+#elif defined(WITH_JAVA_RUNTIME_LIBRARY_CLDC1_1)
+#include "thread-cldc11.hpp"
+#endif
+
 
 /*
  * These are local overrides for various environment variables in Emacs.