* src/threads/threadlist.c: New file.
[cacao.git] / src / threads / threads-common.h
index 2695d52859332a27781e40bd09a185dfc7a5978d..4d0ce24e8a30b0835e2bee68ea12c72b022d8bb0 100644 (file)
@@ -1,9 +1,7 @@
 /* src/threads/threads-common.h - machine independent thread functions
 
-   Copyright (C) 2007 R. Grafl, A. Krall, C. Kruegel,
-   C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
-   E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
-   J. Wenninger, Institut f. Computersprachen - TU Wien
+   Copyright (C) 2007, 2008
+   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
 
    This file is part of CACAO.
 
@@ -22,8 +20,6 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: threads-common.h 7904 2007-05-14 13:29:32Z twisti $
-
 */
 
 
@@ -35,7 +31,7 @@
 
 #include "vm/global.h"
 
-#include "native/jni.h"
+#include "native/llni.h"
 
 #if defined(ENABLE_THREADS)
 # include "threads/native/threads.h"
 
 #if defined(ENABLE_THREADS)
 
-/* typedefs *******************************************************************/
-
-typedef struct threads_table_entry_t threads_table_entry_t;
-typedef struct threads_table_t       threads_table_t;
-
-
 /* thread states **************************************************************/
 
 #define THREAD_STATE_NEW              0
@@ -73,59 +63,75 @@ typedef struct threads_table_t       threads_table_t;
 #define MAX_PRIORITY     10
 
 
-/* threads_table_entry_t *******************************************************
+/* debug **********************************************************************/
+
+#if !defined(NDEBUG)
+# define DEBUGTHREADS(message, thread) \
+       do { \
+               if (opt_DebugThreads) { \
+                       printf("[Thread %-16s: ", message); \
+                       threads_thread_print_info(thread); \
+                       printf("]\n"); \
+               } \
+       } while (0)
+#else
+# define DEBUGTHREADS(message, thread)
+#endif
+
+
+#if defined(__LINUX__)
+/* XXX Remove for exact-GC. */
+extern bool threads_pthreads_implementation_nptl;
+#endif
+
+
+/* inline functions ***********************************************************/
 
-   An entry in the global threads table.
+/* threads_thread_get_object ***************************************************
+
+   Return the java.lang.Thread object for the given thread.
 
 *******************************************************************************/
 
-struct threads_table_entry_t {
-       threadobject *thread;              /* an existing thread                  */
-       s4            next;                /* next free or used index             */
-};
+static inline java_handle_t *threads_thread_get_object(threadobject *t)
+{
+       return LLNI_WRAP(t->object);
+}
 
 
-/* threads_table_t *************************************************************
+/* threads_thread_set_object ***************************************************
 
-   Struct for the global threads table.
+   Set the java.lang.Thread object for the given thread.
 
 *******************************************************************************/
 
-struct threads_table_t {
-       threads_table_entry_t *table;      /* the table, threads[0] is the head   */
-                                          /* of the free list. Real entries      */
-                                                                          /* start at threads[1].                */
-       s4                     size;       /* current size of the table           */
-       s4                     used;       /* number of thread entries            */
-       s4                     daemons;    /* number of daemon thread entries     */
-};
+static inline void threads_thread_set_object(threadobject *t, java_handle_t *object)
+{
+       t->object = LLNI_DIRECT(object);
+}
 
 
 /* function prototypes ********************************************************/
 
 void          threads_preinit(void);
 
-s4            threads_table_add(threadobject *thread);
-void          threads_table_remove(threadobject *thread);
-s4            threads_table_get_threads(void);
-s4            threads_table_get_non_daemons(void);
-threadobject *threads_table_first(void);
-threadobject *threads_table_next(threadobject *thread);
-
-#if !defined(NDEBUG)
-void          threads_table_dump(void);
-#endif
-
 threadobject *threads_thread_new(void);
 void          threads_thread_free(threadobject *t);
+
 bool          threads_thread_start_internal(utf *name, functionptr f);
-void          threads_thread_start(java_lang_Thread *object);
+void          threads_thread_start(java_handle_t *object);
 
 void          threads_thread_print_info(threadobject *t);
 
 ptrint        threads_get_current_tid(void);
-utf          *threads_thread_get_state(threadobject *thread);
-bool          threads_thread_is_alive(threadobject *thread);
+
+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);
+utf          *threads_thread_get_state(threadobject *t);
+
+bool          threads_thread_is_alive(threadobject *t);
 
 void          threads_dump(void);
 void          threads_thread_print_stacktrace(threadobject *thread);
@@ -136,15 +142,26 @@ void          threads_print_stacktrace(void);
 
 void          threads_impl_preinit(void);
 
-void          threads_impl_table_init(void);
-void          threads_table_lock(void);
-void          threads_table_unlock(void);
+void          threads_list_lock(void);
+void          threads_list_unlock(void);
+
+#if defined(ENABLE_GC_CACAO)
+void          threads_mutex_gc_lock(void);
+void          threads_mutex_gc_unlock(void);
+#endif
+
+void          threads_mutex_join_lock(void);
+void          threads_mutex_join_unlock(void);
 
 void          threads_set_current_threadobject(threadobject *thread);
-void          threads_impl_thread_new(threadobject *t);
+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 */
 
 #endif /* _THREADS_COMMON_H */