* src/threads/lock.cpp (sable_flc_waiting): Slight optimization, avoiding
[cacao.git] / src / threads / posix / thread-posix.hpp
index e1e412ecb8402ac1eb945ea55d0ab61bb3250954..424ab84973ae45e08ee0b980b1cba389fbdf02d9 100644 (file)
 #ifndef _THREAD_POSIX_HPP
 #define _THREAD_POSIX_HPP
 
-/* forward typedefs ***********************************************************/
-
-typedef struct threadobject threadobject;
-
-
 #include "config.h"
 
 #include <pthread.h>
@@ -38,68 +33,17 @@ typedef struct threadobject threadobject;
 
 #include "vm/types.h"
 
-#include "mm/memory.h"
+
+// Includes required by Thread.
 
 #if defined(ENABLE_TLH)
-#include "mm/tlh.h"
+# include "mm/tlh.h"
 #endif
 
-#include "native/localref.h"
-
 #include "threads/condition.hpp"
 #include "threads/mutex.hpp"
 
-#include "threads/posix/lock.h"
-
 #include "vm/global.h"
-#include "vm/vm.hpp"
-
-#if defined(ENABLE_GC_CACAO)
-# include "vm/jit/executionstate.h"
-# include "vm/jit/replace.h"
-#endif
-
-#include "vm/jit/stacktrace.hpp"
-
-#if defined(ENABLE_INTRP)
-#include "vm/jit/intrp/intrp.h"
-#endif
-
-#if defined(__DARWIN__)
-# include <mach/mach.h>
-
-typedef struct {
-       Mutex* mutex;
-       Condition* cond;
-       int value;
-} sem_t;
-
-#else
-# include <semaphore.h>
-#endif
-
-
-// FIXME
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* current threadobject *******************************************************/
-
-#if defined(HAVE___THREAD)
-
-#define THREADOBJECT      thread_current
-
-extern __thread threadobject *thread_current;
-
-#else /* defined(HAVE___THREAD) */
-
-#define THREADOBJECT \
-       ((threadobject *) pthread_getspecific(thread_current_key))
-
-extern pthread_key_t thread_current_key;
-
-#endif /* defined(HAVE___THREAD) */
 
 
 /* threadobject ****************************************************************
@@ -117,6 +61,8 @@ extern pthread_key_t thread_current_key;
 #define SUSPEND_REASON_STOPWORLD 2      /* suspended from stop-thw-world      */
 
 
+typedef struct threadobject threadobject;
+
 struct threadobject {
        java_object_t        *object;       /* link to java.lang.Thread object    */
 
@@ -135,6 +81,7 @@ struct threadobject {
        /* for the sable tasuki lock extension */
        bool                  flc_bit;
        struct threadobject  *flc_list;     /* FLC list head for this thread      */
+       struct threadobject  *flc_tail;     /* tail pointer for FLC list          */
        struct threadobject  *flc_next;     /* next pointer for FLC list          */
        java_handle_t        *flc_object;
        Mutex*                flc_lock;     /* controlling access to these fields */
@@ -156,8 +103,8 @@ struct threadobject {
        u1                   *pc;           /* current PC (used for profiling)    */
 
        java_object_t        *_exceptionptr;     /* current exception             */
-       stackframeinfo_t     *_stackframeinfo;   /* current native stackframeinfo */
-       localref_table       *_localref_table;   /* JNI local references          */
+       struct stackframeinfo_t     *_stackframeinfo;   /* current native stackframeinfo */
+       struct localref_table       *_localref_table;   /* JNI local references          */
 
 #if defined(ENABLE_INTRP)
        Cell                 *_global_sp;        /* stack pointer for interpreter */
@@ -170,7 +117,7 @@ struct threadobject {
        executionstate_t     *es;
 #endif
 
-       dumpinfo_t            dumpinfo;     /* dump memory info structure         */
+       struct DumpMemory*    _dumpmemory;     ///< Dump memory structure.
 
 #if defined(ENABLE_DEBUG_FILTER)
        u2                    filterverbosecallctr[2]; /* counters for verbose call filter */
@@ -188,12 +135,27 @@ struct threadobject {
 #if defined(ENABLE_ESCAPE_REASON)
        void *escape_reasons;
 #endif
-
-       listnode_t            linkage;      /* threads-list                       */
-       listnode_t            linkage_free; /* free-list                          */
 };
 
 
+/* current threadobject *******************************************************/
+
+#if defined(HAVE___THREAD)
+
+#define THREADOBJECT      thread_current
+
+extern __thread threadobject *thread_current;
+
+#else /* defined(HAVE___THREAD) */
+
+#define THREADOBJECT \
+       ((threadobject *) pthread_getspecific(thread_current_key))
+
+extern pthread_key_t thread_current_key;
+
+#endif /* defined(HAVE___THREAD) */
+
+
 /* native-world flags *********************************************************/
 
 #if defined(ENABLE_GC_CACAO)
@@ -219,18 +181,62 @@ struct threadobject {
 #endif
 
 
-/* inline functions ***********************************************************/
+// FIXME
+#ifdef __cplusplus
+extern "C" {
+#endif
+inline static threadobject* thread_get_current(void);
+#ifdef __cplusplus
+}
+#endif
+
 
-/* thread_get_current **********************************************************
+// Includes.
+#include "mm/memory.h"
 
-   Return the threadobject of the current thread.
-   
-   RETURN:
-       the current threadobject *
+#include "native/localref.hpp"
 
-*******************************************************************************/
+#include "threads/lock.hpp"
+
+#include "vm/global.h"
+#include "vm/vm.hpp"
+
+#if defined(ENABLE_GC_CACAO)
+# include "vm/jit/executionstate.h"
+# include "vm/jit/replace.hpp"
+#endif
 
-inline static threadobject *thread_get_current(void)
+#if defined(ENABLE_INTRP)
+#include "vm/jit/intrp/intrp.h"
+#endif
+
+#if defined(__DARWIN__)
+# include <mach/mach.h>
+
+typedef struct {
+       Mutex* mutex;
+       Condition* cond;
+       int value;
+} sem_t;
+
+#else
+# include <semaphore.h>
+#endif
+
+
+// FIXME
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* inline functions ***********************************************************/
+
+/**
+ * Return the Thread object of the current thread.
+ *
+ * @return The current Thread object.
+ */
+inline static threadobject* thread_get_current(void)
 {
        threadobject *t;
 
@@ -244,16 +250,12 @@ inline static threadobject *thread_get_current(void)
 }
 
 
-/* thread_set_current **********************************************************
-
-   Set the current thread object.
-   
-   IN:
-      t ... the thread object to set
-
-*******************************************************************************/
-
-inline static void thread_set_current(threadobject *t)
+/**
+ * Set the current Thread object.
+ *
+ * @param t The thread object to set.
+ */
+inline static void thread_set_current(threadobject* t)
 {
 #if defined(HAVE___THREAD)
        thread_current = t;
@@ -268,12 +270,12 @@ inline static void thread_set_current(threadobject *t)
 }
 
 
-inline static stackframeinfo_t *threads_get_current_stackframeinfo(void)
+inline static struct stackframeinfo_t* threads_get_current_stackframeinfo(void)
 {
        return THREADOBJECT->_stackframeinfo;
 }
 
-inline static void threads_set_current_stackframeinfo(stackframeinfo_t *sfi)
+inline static void threads_set_current_stackframeinfo(struct stackframeinfo_t* sfi)
 {
        THREADOBJECT->_stackframeinfo = sfi;
 }