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 /* global variables ***********************************************************/
84 extern methodinfo *thread_method_init;
86 #if defined(__LINUX__)
87 /* XXX Remove for exact-GC. */
88 extern bool threads_pthreads_implementation_nptl;
92 /* inline functions ***********************************************************/
94 /* threads_thread_get_object ***************************************************
96 Return the java.lang.Thread object for the given thread.
98 *******************************************************************************/
100 static inline java_handle_t *threads_thread_get_object(threadobject *t)
102 return LLNI_WRAP(t->object);
106 /* threads_thread_set_object ***************************************************
108 Set the java.lang.Thread object for the given thread.
110 *******************************************************************************/
112 static inline void threads_thread_set_object(threadobject *t, java_handle_t *object)
114 t->object = LLNI_DIRECT(object);
118 /* threads_get_current_object **************************************************
120 Return the Java object of the current thread.
125 *******************************************************************************/
127 inline static java_handle_t *threads_get_current_object(void)
133 o = threads_thread_get_object(t);
139 /* function prototypes ********************************************************/
141 void threads_preinit(void);
142 void threads_init(void);
144 threadobject *threads_thread_new(void);
145 void threads_thread_free(threadobject *t);
147 bool threads_thread_start_internal(utf *name, functionptr f);
148 void threads_thread_start(java_handle_t *object);
150 void threads_thread_print_info(threadobject *t);
152 ptrint threads_get_current_tid(void);
154 void threads_thread_state_runnable(threadobject *t);
155 void threads_thread_state_waiting(threadobject *t);
156 void threads_thread_state_timed_waiting(threadobject *t);
157 void threads_thread_state_terminated(threadobject *t);
158 utf *threads_thread_get_state(threadobject *t);
160 bool threads_thread_is_alive(threadobject *t);
162 void threads_dump(void);
163 void threads_thread_print_stacktrace(threadobject *thread);
164 void threads_print_stacktrace(void);
167 /* implementation specific functions */
169 void threads_impl_preinit(void);
170 void threads_impl_init(void);
172 #if defined(ENABLE_GC_CACAO)
173 void threads_mutex_gc_lock(void);
174 void threads_mutex_gc_unlock(void);
177 void threads_mutex_join_lock(void);
178 void threads_mutex_join_unlock(void);
180 void threads_set_current_threadobject(threadobject *thread);
181 void threads_impl_thread_init(threadobject *t);
182 void threads_impl_thread_clear(threadobject *t);
183 void threads_impl_thread_reuse(threadobject *t);
184 void threads_impl_thread_free(threadobject *t);
185 void threads_impl_thread_start(threadobject *thread, functionptr f);
187 void threads_yield(void);
189 #endif /* ENABLE_THREADS */
191 #endif /* _THREADS_COMMON_H */
195 * These are local overrides for various environment variables in Emacs.
196 * Please do not remove this and leave it at the end of the file, where
197 * Emacs will automagically detect them.
198 * ---------------------------------------------------------------------
201 * indent-tabs-mode: t
205 * vim:noexpandtab:sw=4:ts=4: