1 /* src/threads/threads-common.h - machine independent thread functions
3 Copyright (C) 2007, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 #ifndef _THREADS_COMMON_H
27 #define _THREADS_COMMON_H
32 #include "vm/global.h"
34 #include "native/llni.h"
36 #if defined(ENABLE_THREADS)
37 # include "threads/native/threads.h"
39 # include "threads/none/threads.h"
42 #include "vmcore/utf8.h"
45 /* only define the following stuff with thread enabled ************************/
47 #if defined(ENABLE_THREADS)
49 /* thread states **************************************************************/
51 #define THREAD_STATE_NEW 0
52 #define THREAD_STATE_RUNNABLE 1
53 #define THREAD_STATE_BLOCKED 2
54 #define THREAD_STATE_WAITING 3
55 #define THREAD_STATE_TIMED_WAITING 4
56 #define THREAD_STATE_TERMINATED 5
59 /* thread priorities **********************************************************/
61 #define MIN_PRIORITY 1
62 #define NORM_PRIORITY 5
63 #define MAX_PRIORITY 10
66 /* debug **********************************************************************/
69 # define DEBUGTHREADS(message, thread) \
71 if (opt_DebugThreads) { \
72 printf("[Thread %-16s: ", message); \
73 threads_thread_print_info(thread); \
78 # define DEBUGTHREADS(message, thread)
82 #if defined(__LINUX__)
83 /* XXX Remove for exact-GC. */
84 extern bool threads_pthreads_implementation_nptl;
88 /* inline functions ***********************************************************/
90 /* threads_thread_get_object ***************************************************
92 Return the java.lang.Thread object for the given thread.
94 *******************************************************************************/
96 static inline java_handle_t *threads_thread_get_object(threadobject *t)
98 return LLNI_WRAP(t->object);
102 /* threads_thread_set_object ***************************************************
104 Set the java.lang.Thread object for the given thread.
106 *******************************************************************************/
108 static inline void threads_thread_set_object(threadobject *t, java_handle_t *object)
110 t->object = LLNI_DIRECT(object);
114 /* function prototypes ********************************************************/
116 void threads_preinit(void);
118 threadobject *threads_thread_new(void);
119 void threads_thread_free(threadobject *t);
121 bool threads_thread_start_internal(utf *name, functionptr f);
122 void threads_thread_start(java_handle_t *object);
124 void threads_thread_print_info(threadobject *t);
126 ptrint threads_get_current_tid(void);
127 java_object_t *threads_get_current_object(void);
129 void threads_thread_state_runnable(threadobject *t);
130 void threads_thread_state_waiting(threadobject *t);
131 void threads_thread_state_timed_waiting(threadobject *t);
132 void threads_thread_state_terminated(threadobject *t);
133 utf *threads_thread_get_state(threadobject *t);
135 bool threads_thread_is_alive(threadobject *t);
137 void threads_dump(void);
138 void threads_thread_print_stacktrace(threadobject *thread);
139 void threads_print_stacktrace(void);
142 /* implementation specific functions */
144 void threads_impl_preinit(void);
146 void threads_list_lock(void);
147 void threads_list_unlock(void);
149 #if defined(ENABLE_GC_CACAO)
150 void threads_mutex_gc_lock(void);
151 void threads_mutex_gc_unlock(void);
154 void threads_mutex_join_lock(void);
155 void threads_mutex_join_unlock(void);
157 void threads_set_current_threadobject(threadobject *thread);
158 void threads_impl_thread_init(threadobject *t);
159 void threads_impl_thread_clear(threadobject *t);
160 void threads_impl_thread_reuse(threadobject *t);
161 void threads_impl_thread_free(threadobject *t);
162 void threads_impl_thread_start(threadobject *thread, functionptr f);
164 void threads_yield(void);
166 #endif /* ENABLE_THREADS */
168 #endif /* _THREADS_COMMON_H */
172 * These are local overrides for various environment variables in Emacs.
173 * Please do not remove this and leave it at the end of the file, where
174 * Emacs will automagically detect them.
175 * ---------------------------------------------------------------------
178 * indent-tabs-mode: t
182 * vim:noexpandtab:sw=4:ts=4: